HELP: setting focus to mdi child

  • Thread starter Thread starter Daniel Friend
  • Start date Start date
D

Daniel Friend

Hi,

I have a mdi program which a mdi child (MDI1) opens another mdi child (MD2).
What is happening, the MDI 1 stay focus, after MDI2 appears. The user has
to double click MDI2 to get focus, but the weird thing is that MDI2 is on
top. As you can see from the code, I tried everything to make sure MDI2 has
focus.

Thanks,

Dan

Here is my sample code:

MDIPARENT CODE:
==================
Public Sub BuildNewWindow(ByVal ssCaption As String, ByVal Tag As String,
ByVal Width As Integer, ByVal Height As Integer, ByVal sForm As Form)
sForm.Text = ssCaption
sForm.Width = Width
sForm.Height = Height
sForm.Left = (fDesktop.Width - Width) / 2
sForm.Top = (fDesktop.Height - Height) / 2
sForm.MdiParent = Me
sForm.Tag = Tag
sForm.Show()
sForm.BringToFront()
Application.DoEvents()
sForm.Focus()
sForm.Activate()
sForm.FindForm.Activate()
Application.DoEvents()
End Sub

MDI1 CODE:
==================
Private Sub OpenMsgWindow
Me.Cursor = Cursors.AppStarting
Application.DoEvents()
Dim sForm As Form2
sForm = New Form2
mdiParent.BuildNewWindow("Test Caption", "TAGINFO", 400, 200, sForm)
Me.Cursor = Cursors.Default
Application.DoEvents()
End Sub
 
Hi Daniel,

The only thing you haven't tried is to set the new window as ActiveMdiChild.
Look at the form's ActiveMdiChild property
 
How do you set the value of ActiveMDIChild... it seems to be ReadOnly?


Stoitcho Goutsev (100) said:
Hi Daniel,

The only thing you haven't tried is to set the new window as ActiveMdiChild.
Look at the form's ActiveMdiChild property

--
HTH
Stoitcho Goutsev (100) [C# MVP]


Daniel Friend said:
Hi,

I have a mdi program which a mdi child (MDI1) opens another mdi child
(MD2).
What is happening, the MDI 1 stay focus, after MDI2 appears. The user has
to double click MDI2 to get focus, but the weird thing is that MDI2 is on
top. As you can see from the code, I tried everything to make sure MDI2
has
focus.

Thanks,

Dan

Here is my sample code:

MDIPARENT CODE:
==================
Public Sub BuildNewWindow(ByVal ssCaption As String, ByVal Tag As String,
ByVal Width As Integer, ByVal Height As Integer, ByVal sForm As Form)
sForm.Text = ssCaption
sForm.Width = Width
sForm.Height = Height
sForm.Left = (fDesktop.Width - Width) / 2
sForm.Top = (fDesktop.Height - Height) / 2
sForm.MdiParent = Me
sForm.Tag = Tag
sForm.Show()
sForm.BringToFront()
Application.DoEvents()
sForm.Focus()
sForm.Activate()
sForm.FindForm.Activate()
Application.DoEvents()
End Sub

MDI1 CODE:
==================
Private Sub OpenMsgWindow
Me.Cursor = Cursors.AppStarting
Application.DoEvents()
Dim sForm As Form2
sForm = New Form2
mdiParent.BuildNewWindow("Test Caption", "TAGINFO", 400, 200, sForm)
Me.Cursor = Cursors.Default
Application.DoEvents()
End Sub
 
Hi Daniel!

Calling Avtivate() on your new MdiChild should do it, but I can see that you
have already tried that.

The only thing I can think of is that you create the new MdiChild from
another MdiChild. Have you tried to create your childs from the MdiParent?
But on the other hand i can't think of a reason why you shouldn't be able to
that.

Sorry for the poor help.

Best regards Torben
 
Hi Daniel,

Sorry for my first wrong suggestion. I should've had this checked.

I build a test app out of the code snippets you posted and they works fine
as expected. I guess there is something else going on in your original code.
BTW in my test app I don't have to do anything special. Just set MdiParent
and show the form.
If you haven't managed to handle this problem, pls post some working sample
that demonstrates the problem.


--
Stoitcho Goutsev (100) [C# MVP]
Daniel Friend said:
How do you set the value of ActiveMDIChild... it seems to be ReadOnly?


Stoitcho Goutsev (100) said:
Hi Daniel,

The only thing you haven't tried is to set the new window as ActiveMdiChild.
Look at the form's ActiveMdiChild property

--
HTH
Stoitcho Goutsev (100) [C# MVP]


Daniel Friend said:
Hi,

I have a mdi program which a mdi child (MDI1) opens another mdi child
(MD2).
What is happening, the MDI 1 stay focus, after MDI2 appears. The user has
to double click MDI2 to get focus, but the weird thing is that MDI2 is on
top. As you can see from the code, I tried everything to make sure
MDI2
has
focus.

Thanks,

Dan

Here is my sample code:

MDIPARENT CODE:
==================
Public Sub BuildNewWindow(ByVal ssCaption As String, ByVal Tag As String,
ByVal Width As Integer, ByVal Height As Integer, ByVal sForm As Form)
sForm.Text = ssCaption
sForm.Width = Width
sForm.Height = Height
sForm.Left = (fDesktop.Width - Width) / 2
sForm.Top = (fDesktop.Height - Height) / 2
sForm.MdiParent = Me
sForm.Tag = Tag
sForm.Show()
sForm.BringToFront()
Application.DoEvents()
sForm.Focus()
sForm.Activate()
sForm.FindForm.Activate()
Application.DoEvents()
End Sub

MDI1 CODE:
==================
Private Sub OpenMsgWindow
Me.Cursor = Cursors.AppStarting
Application.DoEvents()
Dim sForm As Form2
sForm = New Form2
mdiParent.BuildNewWindow("Test Caption", "TAGINFO", 400, 200, sForm)
Me.Cursor = Cursors.Default
Application.DoEvents()
End Sub
 
Back
Top