Hi,

I am working on a project in VB.net 2008. I have a problem arising while opening a form as modal from a modeless form. I have attached a project to demonstrate the problem. This demonstration contains three forms with following characteristics.

- “Form1” is main form of the demo application and
- “Form2” is opened as modeless form through “Form1”. It is hidden (using me.hide() method) instead of closing and Cancel the closing in closing event of “Form2”.
- “Form3” is opened as modal form through “Form2”.

Now problem is when I hide “Form2” after closing “Form3”, “Form1” also hides in the background (when some other windows are also open i.e. Windows explorer). I am unable to find a reason for this behavior. This should looks like a common problem and must be encountered by someone else but I am unable to find it on internet. So please help as I need reason and solution for this problem.

Regards,

Hassan

i have downloaded and tried your project. To me, everything seems to be working fine.

In Form1, when calling Form2, remove "Me" from this line:
Form2.Show(Me)

Final result:

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

It works but the problem is when after showing form2 if we selects form1 (without closing form2) it gets behind form1.

Hi,

You can try with topmost like this:

Me.Topmost = True

Setting TopMost property of the form to true will make form1 always on top of not only other forms of applications but all other applications on the screen

Hi,

Yes your right.

In stead of BringToFront(), try calling:

SetForegroundWindow(Me.Handle)

Add this declaration:

Private Declare Function SetForegroundWindow Lib "user32.dll" (ByVal hWnd As IntPtr) As Boolean
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.