|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Beginners problem with multiple formsCan't get my head round something which I reckon should be simple. My app has a main form (frmMain). MdiContainer set to true. A menu item triggers a new form (frmSelect) whose parent is frmMain Button on frmSelect triggers a new form (frmReport) whose parent also needs to be frmMain When frmReport loads and displays I don't want user to see frmSelect, but I don't want to close it. When frmReport closes I want to re-display frmSelect so user can make new selection for report or close Select form My code so far is On frmMain ....... Private Sub mnuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuItem1.Click Dim f1 As New frmSelec f1.MdiParent = Me f1.Show() End Sub On frmSelect ....... Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Dim f2 As New frmReport Me.Visible = False f2.MdiParent = ActiveForm f2.Show() End Sub What do I need to put on the "closed" event of frmReport to get frmSelect to become visible again. And have I used the best method of setting the parent form for frmReport. I had to make frmSelect invisible to get the frmMain as the active form to set it as the parent form. Otherwise a line "f2.mdiparent = me" was trying to set frmSelect as the parent for frmReport Thanks in anticipation Regards Michael Bond
Show quote
Hide quote
"mabond" <mab***@discussions.microsoft.com> schrieb Use f2.mdiparent = me.Mdiparent instead.> Hi > > Can't get my head round something which I reckon should be simple. > > My app has a main form (frmMain). MdiContainer set to true. > A menu item triggers a new form (frmSelect) whose parent is frmMain > Button on frmSelect triggers a new form (frmReport) whose parent > also needs to be frmMain > > When frmReport loads and displays I don't want user to see > frmSelect, but I don't want to close it. > > When frmReport closes I want to re-display frmSelect so user can > make new selection for report or close Select form > > My code so far is > > On frmMain ....... > > Private Sub mnuItem1_Click(ByVal sender As System.Object, ByVal e > As System.EventArgs) Handles mnuItem1.Click > Dim f1 As New frmSelec > f1.MdiParent = Me > f1.Show() > End Sub > > On frmSelect ....... > > Private Sub Button4_Click(ByVal sender As System.Object, ByVal e > As System.EventArgs) Handles Button4.Click > Dim f2 As New frmReport > Me.Visible = False > f2.MdiParent = ActiveForm > f2.Show() > End Sub > > What do I need to put on the "closed" event of frmReport to get > frmSelect to become visible again. And have I used the best method > of setting the parent form for frmReport. I had to make frmSelect > invisible to get the frmMain as the active form to set it as the > parent form. Otherwise a line "f2.mdiparent = me" was trying to set > frmSelect as the parent for frmReport In frmMain, hold the references to frmSelect and frmReport in two fields. Don't use the local variable f1 in mnuItem1_Click but the field in frmMain. Same with frmReport: In Button4_click, raise an event notifying the MDIparent that either frmReport has been opened, or that the MDIparent is to open frmReport on it's own. If you do the former, pass the reference to the new form along. In both cases, store the reference to frmReport in a field in frmMain. Now that you have the reference, you can handle frmReport's closing event. There you can reopen or reshow frmSelect. In addition, handled both Form's closed event to set the references to Nothing. Armin Armin
Thanks for this. The solution to setting the mdiparent worked. I expect the main suggestion also works but I haven't a clue how to put together what you propose ...... and I should know but somehow I've got a mental block with forms in vb.net. If I understand I should have two (invisible?) text boxes on frmMain? But how do I get them to reference frmSelect and frmReport as you suggest. And do I use these references to create a "new" instance of my form as I would with "dim f1 as new frmSelect" Sorry I know I'm being "thick" but since I tried to move from vb6 to vb.net I just cannot grasp how to work with my forms..... even when helpful users such as yourself point me in the right direction Thanks for your help (and patience) so far Regards Michael Bond Show quoteHide quote "Armin Zingler" wrote: > "mabond" <mab***@discussions.microsoft.com> schrieb > > Hi > > > > Can't get my head round something which I reckon should be simple. > > > > My app has a main form (frmMain). MdiContainer set to true. > > A menu item triggers a new form (frmSelect) whose parent is frmMain > > Button on frmSelect triggers a new form (frmReport) whose parent > > also needs to be frmMain > > > > When frmReport loads and displays I don't want user to see > > frmSelect, but I don't want to close it. > > > > When frmReport closes I want to re-display frmSelect so user can > > make new selection for report or close Select form > > > > My code so far is > > > > On frmMain ....... > > > > Private Sub mnuItem1_Click(ByVal sender As System.Object, ByVal e > > As System.EventArgs) Handles mnuItem1.Click > > Dim f1 As New frmSelec > > f1.MdiParent = Me > > f1.Show() > > End Sub > > > > On frmSelect ....... > > > > Private Sub Button4_Click(ByVal sender As System.Object, ByVal e > > As System.EventArgs) Handles Button4.Click > > Dim f2 As New frmReport > > Me.Visible = False > > f2.MdiParent = ActiveForm > > f2.Show() > > End Sub > > > > What do I need to put on the "closed" event of frmReport to get > > frmSelect to become visible again. And have I used the best method > > of setting the parent form for frmReport. I had to make frmSelect > > invisible to get the frmMain as the active form to set it as the > > parent form. Otherwise a line "f2.mdiparent = me" was trying to set > > frmSelect as the parent for frmReport > > > Use f2.mdiparent = me.Mdiparent instead. > > In frmMain, hold the references to frmSelect and frmReport in two fields. > Don't use the local variable f1 in mnuItem1_Click but the field in frmMain. > Same with frmReport: In Button4_click, raise an event notifying the > MDIparent that either frmReport has been opened, or that the MDIparent is to > open frmReport on it's own. If you do the former, pass the reference to the > new form along. In both cases, store the reference to frmReport in a field > in frmMain. Now that you have the reference, you can handle frmReport's > closing event. There you can reopen or reshow frmSelect. In addition, > handled both Form's closed event to set the references to Nothing. > > > Armin > >
Show quote
Hide quote
"mabond" <mab***@discussions.microsoft.com> schrieb No, no textboxes. Variables at class level are called "fields":> > "Armin Zingler" wrote: > > > "mabond" <mab***@discussions.microsoft.com> schrieb > > > Hi > > > > > > Can't get my head round something which I reckon should be > > > simple. > > > > > > My app has a main form (frmMain). MdiContainer set to true. > > > A menu item triggers a new form (frmSelect) whose parent is > > > frmMain Button on frmSelect triggers a new form (frmReport) > > > whose parent > > > also needs to be frmMain > > > > > > When frmReport loads and displays I don't want user to see > > > frmSelect, but I don't want to close it. > > > > > > When frmReport closes I want to re-display frmSelect so user can > > > make new selection for report or close Select form > > > > > > My code so far is > > > > > > On frmMain ....... > > > > > > Private Sub mnuItem1_Click(ByVal sender As System.Object, > > > ByVal e As System.EventArgs) Handles mnuItem1.Click > > > Dim f1 As New frmSelec > > > f1.MdiParent = Me > > > f1.Show() > > > End Sub > > > > > > On frmSelect ....... > > > > > > Private Sub Button4_Click(ByVal sender As System.Object, > > > ByVal e As System.EventArgs) Handles Button4.Click > > > Dim f2 As New frmReport > > > Me.Visible = False > > > f2.MdiParent = ActiveForm > > > f2.Show() > > > End Sub > > > > > > What do I need to put on the "closed" event of frmReport to get > > > frmSelect to become visible again. And have I used the best > > > method of setting the parent form for frmReport. I had to make > > > frmSelect invisible to get the frmMain as the active form to set > > > it as the > > > parent form. Otherwise a line "f2.mdiparent = me" was trying to > > > set frmSelect as the parent for frmReport > > > > > > Use f2.mdiparent = me.Mdiparent instead. > > > > In frmMain, hold the references to frmSelect and frmReport in two > > fields. Don't use the local variable f1 in mnuItem1_Click but the > > field in frmMain. Same with frmReport: In Button4_click, raise an > > event notifying the MDIparent that either frmReport has been > > opened, or that the MDIparent is to open frmReport on it's own. If > > you do the former, pass the reference to the new form along. In > > both cases, store the reference to frmReport in a field in > > frmMain. Now that you have the reference, you can handle > > frmReport's closing event. There you can reopen or reshow > > frmSelect. In addition, handled both Form's closed event to set > > the references to Nothing. > > Thanks for this. The solution to setting the mdiparent worked. > > I expect the main suggestion also works but I haven't a clue how to > put together what you propose ...... and I should know but somehow > I've got a mental block with forms in vb.net. > > If I understand I should have two (invisible?) text boxes on > frmMain? But how do I get them to reference frmSelect and frmReport > as you suggest. And do I use these references to create a "new" > instance of my form as I would with "dim f1 as new frmSelect" > > Sorry I know I'm being "thick" but since I tried to move from vb6 to > vb.net I just cannot grasp how to work with my forms..... even when > helpful users such as yourself point me in the right direction http://msdn.microsoft.com/library/en-us/cpguide/html/cpcontypemembers.asp http://msdn.microsoft.com/library/en-us/vbcn7/html/vbconProperties.asp What I meant was: frmMain: Private WithEvents ReportForm As frmReport Private WithEvents SelectForm As frmSelect Private Sub Button1_Click( _ ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles Button1.Click SelectForm = New frmSelect SelectForm.MdiParent = Me SelectForm.Show() End Sub Private Sub SelectForm_Closed( _ ByVal sender As Object, ByVal e As System.EventArgs) _ Handles SelectForm.Closed SelectForm = Nothing End Sub Private Sub ReportForm_Closed( _ ByVal sender As Object, ByVal e As System.EventArgs) _ Handles ReportForm.Closed SelectForm.Show() ReportForm = Nothing End Sub Private Sub SelectForm_ReportOpened( _ ByVal Form As frmReport) _ Handles SelectForm.ReportOpened ReportForm = Form End Sub frmSelect: Public Event ReportOpened(ByVal Form As frmReport) Private Sub Button1_Click( _ ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles Button1.Click Dim f As New frmReport f.MdiParent = Me.MdiParent f.Show() RaiseEvent ReportOpened(f) End Sub I didn't pay attention on frmSelect being closed. Of course, this is only one possible approach - such solutions are often very individual and depend on many black horses. Armin Armin
Thanks. I can understand the way you've laid this out and can see the approach I should be using. I appreciate the help. Many thanks Regards Michael Bond information Manager RNID Typetalk - National Telephone Relay Service for the Deaf (UK) Show quoteHide quote "Armin Zingler" wrote: > "mabond" <mab***@discussions.microsoft.com> schrieb > > > > "Armin Zingler" wrote: > > > > > "mabond" <mab***@discussions.microsoft.com> schrieb > > > > Hi > > > > > > > > Can't get my head round something which I reckon should be > > > > simple. > > > > > > > > My app has a main form (frmMain). MdiContainer set to true. > > > > A menu item triggers a new form (frmSelect) whose parent is > > > > frmMain Button on frmSelect triggers a new form (frmReport) > > > > whose parent > > > > also needs to be frmMain > > > > > > > > When frmReport loads and displays I don't want user to see > > > > frmSelect, but I don't want to close it. > > > > > > > > When frmReport closes I want to re-display frmSelect so user can > > > > make new selection for report or close Select form > > > > > > > > My code so far is > > > > > > > > On frmMain ....... > > > > > > > > Private Sub mnuItem1_Click(ByVal sender As System.Object, > > > > ByVal e As System.EventArgs) Handles mnuItem1.Click > > > > Dim f1 As New frmSelec > > > > f1.MdiParent = Me > > > > f1.Show() > > > > End Sub > > > > > > > > On frmSelect ....... > > > > > > > > Private Sub Button4_Click(ByVal sender As System.Object, > > > > ByVal e As System.EventArgs) Handles Button4.Click > > > > Dim f2 As New frmReport > > > > Me.Visible = False > > > > f2.MdiParent = ActiveForm > > > > f2.Show() > > > > End Sub > > > > > > > > What do I need to put on the "closed" event of frmReport to get > > > > frmSelect to become visible again. And have I used the best > > > > method of setting the parent form for frmReport. I had to make > > > > frmSelect invisible to get the frmMain as the active form to set > > > > it as the > > > > parent form. Otherwise a line "f2.mdiparent = me" was trying to > > > > set frmSelect as the parent for frmReport > > > > > > > > > Use f2.mdiparent = me.Mdiparent instead. > > > > > > In frmMain, hold the references to frmSelect and frmReport in two > > > fields. Don't use the local variable f1 in mnuItem1_Click but the > > > field in frmMain. Same with frmReport: In Button4_click, raise an > > > event notifying the MDIparent that either frmReport has been > > > opened, or that the MDIparent is to open frmReport on it's own. If > > > you do the former, pass the reference to the new form along. In > > > both cases, store the reference to frmReport in a field in > > > frmMain. Now that you have the reference, you can handle > > > frmReport's closing event. There you can reopen or reshow > > > frmSelect. In addition, handled both Form's closed event to set > > > the references to Nothing. > > > > Thanks for this. The solution to setting the mdiparent worked. > > > > I expect the main suggestion also works but I haven't a clue how to > > put together what you propose ...... and I should know but somehow > > I've got a mental block with forms in vb.net. > > > > If I understand I should have two (invisible?) text boxes on > > frmMain? But how do I get them to reference frmSelect and frmReport > > as you suggest. And do I use these references to create a "new" > > instance of my form as I would with "dim f1 as new frmSelect" > > > > Sorry I know I'm being "thick" but since I tried to move from vb6 to > > vb.net I just cannot grasp how to work with my forms..... even when > > helpful users such as yourself point me in the right direction > > No, no textboxes. Variables at class level are called "fields": > > http://msdn.microsoft.com/library/en-us/cpguide/html/cpcontypemembers.asp > http://msdn.microsoft.com/library/en-us/vbcn7/html/vbconProperties.asp > > > What I meant was: > > frmMain: > Private WithEvents ReportForm As frmReport > Private WithEvents SelectForm As frmSelect > > Private Sub Button1_Click( _ > ByVal sender As System.Object, ByVal e As System.EventArgs) _ > Handles Button1.Click > > SelectForm = New frmSelect > SelectForm.MdiParent = Me > SelectForm.Show() > > End Sub > > Private Sub SelectForm_Closed( _ > ByVal sender As Object, ByVal e As System.EventArgs) _ > Handles SelectForm.Closed > > SelectForm = Nothing > > End Sub > Private Sub ReportForm_Closed( _ > ByVal sender As Object, ByVal e As System.EventArgs) _ > Handles ReportForm.Closed > > SelectForm.Show() > ReportForm = Nothing > > End Sub > Private Sub SelectForm_ReportOpened( _ > ByVal Form As frmReport) _ > Handles SelectForm.ReportOpened > > ReportForm = Form > > End Sub > > > frmSelect: > > Public Event ReportOpened(ByVal Form As frmReport) > > Private Sub Button1_Click( _ > ByVal sender As System.Object, ByVal e As System.EventArgs) _ > Handles Button1.Click > > Dim f As New frmReport > f.MdiParent = Me.MdiParent > f.Show() > RaiseEvent ReportOpened(f) > > End Sub > > > I didn't pay attention on frmSelect being closed. Of course, this is only > one possible approach - such solutions are often very individual and depend > on many black horses. > > > Armin > > Armin
Just to let you know I've finished coding with the pointers you gave me. Only made one change .... added a line in "frmSelcect .... button_click" to make the select window visible = false (rather than close). Everything works as desired ..... AND, more importantly, I think I've grasped a little bit more about how to handle forms in my apps. Thanks very much for your help Regards Michael Bond Information Manager, RNID Typetalk, UK National Telephone Relay Service for the Deaf. Show quoteHide quote "Armin Zingler" wrote: > "mabond" <mab***@discussions.microsoft.com> schrieb > > > > "Armin Zingler" wrote: > > > > > "mabond" <mab***@discussions.microsoft.com> schrieb > > > > Hi > > > > > > > > Can't get my head round something which I reckon should be > > > > simple. > > > > > > > > My app has a main form (frmMain). MdiContainer set to true. > > > > A menu item triggers a new form (frmSelect) whose parent is > > > > frmMain Button on frmSelect triggers a new form (frmReport) > > > > whose parent > > > > also needs to be frmMain > > > > > > > > When frmReport loads and displays I don't want user to see > > > > frmSelect, but I don't want to close it. > > > > > > > > When frmReport closes I want to re-display frmSelect so user can > > > > make new selection for report or close Select form > > > > > > > > My code so far is > > > > > > > > On frmMain ....... > > > > > > > > Private Sub mnuItem1_Click(ByVal sender As System.Object, > > > > ByVal e As System.EventArgs) Handles mnuItem1.Click > > > > Dim f1 As New frmSelec > > > > f1.MdiParent = Me > > > > f1.Show() > > > > End Sub > > > > > > > > On frmSelect ....... > > > > > > > > Private Sub Button4_Click(ByVal sender As System.Object, > > > > ByVal e As System.EventArgs) Handles Button4.Click > > > > Dim f2 As New frmReport > > > > Me.Visible = False > > > > f2.MdiParent = ActiveForm > > > > f2.Show() > > > > End Sub > > > > > > > > What do I need to put on the "closed" event of frmReport to get > > > > frmSelect to become visible again. And have I used the best > > > > method of setting the parent form for frmReport. I had to make > > > > frmSelect invisible to get the frmMain as the active form to set > > > > it as the > > > > parent form. Otherwise a line "f2.mdiparent = me" was trying to > > > > set frmSelect as the parent for frmReport > > > > > > > > > Use f2.mdiparent = me.Mdiparent instead. > > > > > > In frmMain, hold the references to frmSelect and frmReport in two > > > fields. Don't use the local variable f1 in mnuItem1_Click but the > > > field in frmMain. Same with frmReport: In Button4_click, raise an > > > event notifying the MDIparent that either frmReport has been > > > opened, or that the MDIparent is to open frmReport on it's own. If > > > you do the former, pass the reference to the new form along. In > > > both cases, store the reference to frmReport in a field in > > > frmMain. Now that you have the reference, you can handle > > > frmReport's closing event. There you can reopen or reshow > > > frmSelect. In addition, handled both Form's closed event to set > > > the references to Nothing. > > > > Thanks for this. The solution to setting the mdiparent worked. > > > > I expect the main suggestion also works but I haven't a clue how to > > put together what you propose ...... and I should know but somehow > > I've got a mental block with forms in vb.net. > > > > If I understand I should have two (invisible?) text boxes on > > frmMain? But how do I get them to reference frmSelect and frmReport > > as you suggest. And do I use these references to create a "new" > > instance of my form as I would with "dim f1 as new frmSelect" > > > > Sorry I know I'm being "thick" but since I tried to move from vb6 to > > vb.net I just cannot grasp how to work with my forms..... even when > > helpful users such as yourself point me in the right direction > > No, no textboxes. Variables at class level are called "fields": > > http://msdn.microsoft.com/library/en-us/cpguide/html/cpcontypemembers.asp > http://msdn.microsoft.com/library/en-us/vbcn7/html/vbconProperties.asp > > > What I meant was: > > frmMain: > Private WithEvents ReportForm As frmReport > Private WithEvents SelectForm As frmSelect > > Private Sub Button1_Click( _ > ByVal sender As System.Object, ByVal e As System.EventArgs) _ > Handles Button1.Click > > SelectForm = New frmSelect > SelectForm.MdiParent = Me > SelectForm.Show() > > End Sub > > Private Sub SelectForm_Closed( _ > ByVal sender As Object, ByVal e As System.EventArgs) _ > Handles SelectForm.Closed > > SelectForm = Nothing > > End Sub > Private Sub ReportForm_Closed( _ > ByVal sender As Object, ByVal e As System.EventArgs) _ > Handles ReportForm.Closed > > SelectForm.Show() > ReportForm = Nothing > > End Sub > Private Sub SelectForm_ReportOpened( _ > ByVal Form As frmReport) _ > Handles SelectForm.ReportOpened > > ReportForm = Form > > End Sub > > > frmSelect: > > Public Event ReportOpened(ByVal Form As frmReport) > > Private Sub Button1_Click( _ > ByVal sender As System.Object, ByVal e As System.EventArgs) _ > Handles Button1.Click > > Dim f As New frmReport > f.MdiParent = Me.MdiParent > f.Show() > RaiseEvent ReportOpened(f) > > End Sub > > > I didn't pay attention on frmSelect being closed. Of course, this is only > one possible approach - such solutions are often very individual and depend > on many black horses. > > > Armin > > "mabond" <mab***@discussions.microsoft.com> schrieb You're welcome!> Armin > > Just to let you know I've finished coding with the pointers you gave > me. Only made one change .... added a line in "frmSelcect .... > button_click" to make the select window visible = false (rather than > close). > > Everything works as desired ..... AND, more importantly, I think > I've grasped a little bit more about how to handle forms in my apps. > > Thanks very much for your help Armin Handle the "Closing" event of the forms, not the "Closed" event.
Show quoteHide quote "mabond" <mab***@discussions.microsoft.com> wrote in message news:7803CE2B-7D15-48E7-9A2B-69946F71BC73@microsoft.com... > Hi > > Can't get my head round something which I reckon should be simple. > > My app has a main form (frmMain). MdiContainer set to true. > A menu item triggers a new form (frmSelect) whose parent is frmMain > Button on frmSelect triggers a new form (frmReport) whose parent also needs > to be frmMain > > When frmReport loads and displays I don't want user to see frmSelect, but I > don't want to close it. > > When frmReport closes I want to re-display frmSelect so user can make new > selection for report or close Select form > > My code so far is > > On frmMain ....... > > Private Sub mnuItem1_Click(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles mnuItem1.Click > Dim f1 As New frmSelec > f1.MdiParent = Me > f1.Show() > End Sub > > On frmSelect ....... > > Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles Button4.Click > Dim f2 As New frmReport > Me.Visible = False > f2.MdiParent = ActiveForm > f2.Show() > End Sub > > What do I need to put on the "closed" event of frmReport to get frmSelect to > become visible again. And have I used the best method of setting the parent > form for frmReport. I had to make frmSelect invisible to get the frmMain as > the active form to set it as the parent form. Otherwise a line "f2.mdiparent > = me" was trying to set frmSelect as the parent for frmReport > > Thanks in anticipation > > Regards > > Michael Bond |
|||||||||||||||||||||||