Click here to Skip to main content
15,905,967 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm having a problem (most likely an understanding) with forms in WinCE. So as i don't post complicated code i have replicated the problem in a simple example;

VB
Public Class frmMain
Private Sub btnForm2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnForm2.Click
        Form2.Show()
    End Sub
End Class

Public Class Form2

    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        Me.Hide()
    End Sub

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'some code to add controls on the fly
    End Sub
End Class

This works well with the buttons opening and closing the forms as required however, i want to change the Form 2 event (btnClose) so that the form closes thus removing any controls i add on the fly. If i change the event to Me.Close() the form closes but i cannot open it again with the button in Form 1 ie: Form2.Show().(Why i don't know).
I have tried removing the controls on Form2 just before the hide, but on showing the form again (Form2.Show) it doesn't goto Form2_Load so new controls are not added thus my reason for wanting to 'Close' Form2.
So my question is why does the Form2.Close stop the form from showing a second time and what is the workaround? - i'm sure this is just my poor understanding of WinCE forms. Any ideas?
Posted

1 solution

Ok i have one solution - which works - though is untidy in my view;

Basically just call the the 'Load' Sub - after making it Public of course.

VB
Public Class frmMain

    Private Sub btnForm2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnForm2.Click
        Form2.Show()
        Form2.Form2_Load()
    End Sub
End Class
 
Public Class Form2

    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        Me.Hide()
        'for each ctr in me
        'delete controls
        'next
        frmMain.Show()
    End Sub

    Public Sub Form2_Load() Handles MyBase.Load
        'some code to add controls on the fly
    End Sub
End Class


Would still love to hear suggestions etc...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900