MDI Menu Icon - not showing - then showing

M

Miro

VB 2005 Express.

I can create a simple MDI app, with 2 forms.
On Form1
I add a menustrip on top - and click on ( Insert Standard Items )
Add a ToolStrip as well and add 2 buttons.

On Form2, add a form Icon
On Form3, add a form Icon

Now, On form1 here is the code I have.
======
Public Class Form1

Public Shared fForm2 As Form2 = Nothing
Public Shared fForm3 As Form3 = Nothing


Private Sub ToolStripButton1_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ToolStripButton1.Click
fForm2 = New Form2
fForm2.MdiParent = Me
fForm2.WindowState = FormWindowState.Maximized
fForm2.Show()

End Sub

Private Sub ToolStripButton2_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ToolStripButton2.Click
fForm3 = New Form3
fForm3.MdiParent = Me
fForm3.WindowState = FormWindowState.Maximized
fForm3.Show()
End Sub
End Class
======

When I run this app, and click on button1, form2 opens, but without the
Form Icon in the menustrip. Instead it shows the default VS icon.
Now Click on Fom2 Button, and it shows the new form again with the
default vs icon. Now click the "x" / close the form3 and now form2 is
still showing - and now with an icon.

I have checked the msdn formus and have found somewhat of a solution,
and as I understand it, it is below.

What I had to do was this:
Public Class Form2

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.WindowState = FormWindowState.Normal
End Sub

Private Sub Form2_Shown(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Shown
Me.WindowState = FormWindowState.Maximized
End Sub
End Class


So now I am wondering - ( i am a newbie ) but i think i have the
terminology,... is there a way I can make a Sub that handles all my
child forms? So i dont have to keep adding this "fix" code to all my
forms.

Im assuming I have to put something in the Handles <all forms.load> but
im not sure what that is.



Thanks

Miro
 
G

Guest

Thank,
exactly what I wanted to do,
I have done it that way:

In the MDI from i am declaring instance of the child form(s) :

frm_Child1 = new FormChild
AddHandler frm_Child1.Shown, AddressOf ShowChildIcon
frm_Child1.Name = formText
frm_Child1.MdiParent = Me
frm_Child1.show
and sub:

Private Sub ShowChildIcon(ByVal sender As Object, ByVal e As
System.EventArgs)
sender.windowstate = FormWindowState.Maximized
End Sub

you can use this sub for all you child forms.
Only add handler for them when you create their instances
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top