SetFocus

sethindeed

Well-known member
Joined
Dec 31, 1969
Messages
118
Location
Montreal Canada
I have an MDIForm and some child forms.
I already wrote a routine that prevent a form from opening two times.
What I want to do next is that when the user tries to open an already opened form, I want this form to be in focus.
I used to do it quite easily in VB6 with the SetFocus method but this method is gone in .NET.
Anybody knows how can I do what I want ?
thx !
 
You can use a For Each to cycle through all open MDIForms and check
to see if its an instance of the particular form using (I think) the TypeOf
operator (If TypeOf theForm Is Form2 Then theForm.Focus(), or
something similar).
 
Actually, I have some difficulties with the For Each syntax.

For each frm in Forms does not work

For each frm in System.Windows.Forms does not work neither :(
 
There is no more Forms collection in .NET, youll have to create your own if you want this feature. An MDI form does keep track of its children. You can use:
C#:
foreach(Form f in this.MdiChildren)
{
    // Use f.Show() or whatever you need...
}

-ner
 
Back
Top