By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,693 Members | 1,267 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,693 IT Pros & Developers. It's quick & easy.

Beginners problem with multiple forms

P: n/a
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
Feb 14 '06 #1
Share this Question
Share on Google+
7 Replies


P: n/a
"mabond" <ma****@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

Feb 14 '06 #2

P: n/a
Handle the "Closing" event of the forms, not the "Closed" event.

"mabond" <ma****@discussions.microsoft.com> wrote in message
news:78**********************************@microsof t.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

Feb 14 '06 #3

P: n/a
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

"Armin Zingler" wrote:
"mabond" <ma****@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

Feb 14 '06 #4

P: n/a
"mabond" <ma****@discussions.microsoft.com> schrieb

"Armin Zingler" wrote:
"mabond" <ma****@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...ypemembers.asp
http://msdn.microsoft.com/library/en...Properties.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

Feb 14 '06 #5

P: n/a
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)

"Armin Zingler" wrote:
"mabond" <ma****@discussions.microsoft.com> schrieb

"Armin Zingler" wrote:
"mabond" <ma****@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...ypemembers.asp
http://msdn.microsoft.com/library/en...Properties.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

Feb 14 '06 #6

P: n/a
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.

"Armin Zingler" wrote:
"mabond" <ma****@discussions.microsoft.com> schrieb

"Armin Zingler" wrote:
"mabond" <ma****@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...ypemembers.asp
http://msdn.microsoft.com/library/en...Properties.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

Feb 15 '06 #7

P: n/a
"mabond" <ma****@discussions.microsoft.com> schrieb
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

You're welcome!
Armin
Feb 15 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.