Click here to Skip to main content
16,011,947 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
i have designed a form whose start position is centerscreen and in that form i have a button when the button is clicked i instantiate another form whose start position is center parent but what happens is this form gets hidden inside the previous form created but i need it in front of it how to set the position correctly

thanks
Posted

 
Share this answer
 
What's your problem? If you create and show a new form, it will go on top of the first form, as you wanted. If may cover the first form, so what?

By the way, parent-child relationship between forms is not functional (even though Form is Control with Control.Parent and you actually can make a form a parent of another form, I recommend you never do so), and the two forms you described are not child-parent, of course.

Instead, I strongly recommend to use the relationship Owner/Owned form. Use the property Form.Owner to make all forms owned by the main form. This is important for application integrity: activation of one form or application will always put all application's form activate together in Z-order which will not allow a form from any other application to come between your forms.

See http://msdn.microsoft.com/en-us/library/system.windows.forms.form.aspx[^].

Better yet, avoid multiple forms; use just one with more complex container controls like TabControl. What are now your separate form will become the tab pages. There are many other good styles based on a single form; look at Visual Studio, for example. Most important thing here is not using MDI.

—SA
 
Share this answer
 
I also faced the same proble at the time of my project Development.
I found one solution on that just create one Subrutine CloseAllOpenForm
VB
Private Sub CloseAllOpenForms()
Form1.Close() 'It will Close Form1 if it is open.
Form2.Close() 'It will Close Form2 if it is open
End Sub

Mentione all forms you are using in your applicaiton.
After that befor opening new form just call above method like
VB
CloseAllForms() 'It will close all open forms
Form1.Show()    'It will show your newly opened form.

It will Solve your problem because no other form is opened only your newly opened form will be shown in MDI Form.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900