VB.Net Mdichild focus problem ?

N

nomenklatura

Hi,
I have a main menu which parent mdi form
and i opening two mdi child form (frm1,frm2) with listview doubleclick
event on main menu..
ex:
Dim frm As New frm1

frm.MdiParent = Me

frm.Show()

Ok, there isn't problem
But when two child forms opened, and try this forms open again , i couldn't
use top code , because this code create new same form ..
So i try to activate (focus) opened child form if it is loaded..
I use boolen variabel and set frm1loaded event isfrm1loaded=true when frm1
first created..
Maybe you have a better idea this problem..
So my code:
If Isfrm1 = True Then

frm1.ActiveForm.Focus()

Else

Dim frm As New frm1

frm.MdiParent = Me

frm.Show()

End If


But frm1.ActiveForm.Focus() couldn't work..???
If this frm1 behind to frm2, it isn't come front to frm2 ..
How can i ?
If i use visualbasic 6 , solve tihis problem very easy
But .net form management very complex and i colund't find examples in msdn..

Thanks in advance..


Note:I am from Turkey and my primitive language is Turkish.. Execuse for my
english :)
 
J

Jose Luis Manners

You can enumarate the child forms of a parent with the following code:

System.Windows.Forms.Form[] mdiChildren = this.MdiChildren;
for (int i = 0; i < mdiChildren.Length; i++)
{
System.Windows.Forms.Form frm = (Form) mdiChildren.GetValue(i);
// and now you can use the object frm to check whatever you want
}


I hope this helps.

Jose Luis Manners, MCP
 
J

Jose Luis Manners

You can even do shomething like this:

for (int i = 0; i < this.MdiChildren.Length; i++)
{
System.Windows.Forms.Form frm = (Form) this.MdiChildren.GetValue(i);

if (frm.Text.Equals("Child Form 1"))
{
frm.Activate();
break;
}
}

Regards,

Jose Luis Manners, MCP
 
N

nomenklatura

Thanks a lot..
But i have got about 200 forms ..
so for next loop is very slow method for this project

"Jose Luis Manners" <jlmanners(-arroba-)acm.org>, iletide þunu yazdý
news:[email protected]...
 

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