Click here to Skip to main content
13,149,099 members (52,281 online)
Rate this:
 
Please Sign up or sign in to vote.
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;

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 28-Sep-12 4:14am

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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.

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...
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web04 | 2.8.170924.2 | Last Updated 28 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100