Form is hiding in background

Developer111

Member
Joined
Apr 21, 2010
Messages
24
Programming Experience
5-10
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
 

Attachments

  • DemoApp.zip
    19.8 KB · Views: 19
Last edited by a moderator:
When you close the 'Form2' after closing 'Form3', the 'Form1' is not hiding, it is on the minimized state.

Just use 'Form1.BringToFront()' after Me.Hide() in the click event of the 'Hide me' button of the 'Form2'.
 
The solution you propose works, thanks for your quick reply. I tried that earlier but in the closing event which didn't work. The solution is fine for me but can you please reason why this is happening, as why Form1 gets minimized? Is the usage of forms like that cause that?
 
Sorry, I'm not sure why it happens so.

In the 'Form1' you have used the code 'Form2.Show(Me)'. It will make 'Form1' as the owner of 'Form2'. I think, calling the hide method of the child form will trigger some change in its parent form. This may be the reason for your issue.

Instead of using 'Form1.BringToFront()' in 'Form2', modifying the code of 'Form1' to 'Form2.Show' also will resolve your issue.

PS: You can know the owner of the form by using the code: Me.Owner.Name
 
Back
Top