Form position

J

John

Hi

I have a panel to which I have added several forms as follows;

form1 = New frmone
form1.TopLevel = False
Me.MyPanel.Controls.Add(form1)
form1.BringToFront()

form2 = New frmtwo
form2.TopLevel = False
Me.MyPanel.Controls.Add(form2)
form2.BringToFront()

Is there a way to know which form is currently at the top?

Thanks

Regards
 
H

Herfried K. Wagner [MVP]

* "John said:
I have a panel to which I have added several forms as follows;

form1 = New frmone
form1.TopLevel = False
Me.MyPanel.Controls.Add(form1)
form1.BringToFront()

form2 = New frmtwo
form2.TopLevel = False
Me.MyPanel.Controls.Add(form2)
form2.BringToFront()

Is there a way to know which form is currently at the top?

Add a variable to the container form and set it to the active form if
one of the form gets, for example, clicked.
 
J

John

OK, I have dim f as form and f = form1 or f = form2 as the case maybe. Now
how can I call a procedure within either form1 or form2 using f as
reference? f.mysub() does not work.

Thanks

Regards
 
H

Herfried K. Wagner [MVP]

* "John said:
OK, I have dim f as form and f = form1 or f = form2 as the case maybe. Now
how can I call a procedure within either form1 or form2 using f as
reference? f.mysub() does not work.

\\\
If TypeOf f Is Form1 Then
DirectCast(f, Form1).MySub()
ElseIf ... Then
...
End If
///
 
J

John

Thanks. Can I not have; DirectCast(f, TypeOf f).MySub() just to save on
coding?

Regards
 
H

Herfried K. Wagner [MVP]

* "John said:
Thanks. Can I not have; DirectCast(f, TypeOf f).MySub() just to save on
coding?

No. You can use late binding (you will have to disable 'Option
Strict'), but that's not "recommended". Or you can derive all child
form types from a common base form which defines the method or let them
implement an interface. Then you can declare the variable in the type
of that class or interface and won't need to cast.
 

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