By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,234 Members | 1,869 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,234 IT Pros & Developers. It's quick & easy.

Form.TopMost Conflicts With MsgBox

P: n/a
Don
I've got a form which (in a roundabout manner) calls a second form into
existence which has its TopMost property set (the first form is not the
parent of this second form because of the roundabout manner in which the
second form is created and displayed). The user can then still work on the
first form while the second form floats around above it.

If the first form displays a messagebox via the MsgBox method, the
messagebox appears behing the second, TopMost form and is unreachable. Is
there anyway around this odd behavior? Does this have something to do with
the second form not having the first as its parent?

- Don
Mar 23 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Don
Here's some quick code you can try to reproduce the problem.

- First, create a new, blank project.
- Create two forms, named Form1 and Form2.
- On Form1, place two buttons named Button1 and Button2.
- Post the following code into Form1's code module:
Private WithEvents SecondForm As Form2 = New Form2

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

SecondForm.TopMost = True
SecondForm.Show()

End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click

MsgBox("test")

End Sub
Press Button1 first to bring up the second form, then press Button2. The
messagebox appears behind the second form. :(

- Don
Mar 23 '06 #2

P: n/a
Hi Don, that behaviour is normal, because of TopMost.

See if something like the following can equally fit your needs:

Private WithEvents SecondForm As Form2 = New Form2

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
SecondForm.TopMost = False
SecondForm.Owner = Me
SecondForm.Show()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
MsgBox("test")
End Sub

-tom

Don ha scritto:
Here's some quick code you can try to reproduce the problem.

- First, create a new, blank project.
- Create two forms, named Form1 and Form2.
- On Form1, place two buttons named Button1 and Button2.
- Post the following code into Form1's code module:
Private WithEvents SecondForm As Form2 = New Form2

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

SecondForm.TopMost = True
SecondForm.Show()

End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click

MsgBox("test")

End Sub
Press Button1 first to bring up the second form, then press Button2. The
messagebox appears behind the second form. :(

- Don


Mar 23 '06 #3

P: n/a
Don
Oh, that's perfect! Thanks.

- Don

<to**************@uniroma1.it> wrote in message
news:11*********************@v46g2000cwv.googlegro ups.com...
Hi Don, that behaviour is normal, because of TopMost.

See if something like the following can equally fit your needs:

Private WithEvents SecondForm As Form2 = New Form2

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
SecondForm.TopMost = False
SecondForm.Owner = Me
SecondForm.Show()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
MsgBox("test")
End Sub

-tom

Mar 23 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.