Click here to Skip to main content
15,909,652 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
Hi,

I have a form in which when I click a button I get another form. This second which appears at the center of the screen.

Now my requirement is when I click outside of the form I should get the parent form in front and this second form should be at the back of the form.

What should I set in the form properties so that I can get this done?
Posted
Updated 20-Nov-11 4:00am
v2

Take Two Forms Form1 and Form2, Take one button on Form1
Write the Following Code on the Button to Open another Form and to Set Focuse on that Form.
VB
Private Sub Button1_Click(ByVal sender As Object,ByVal e As EventArgs) Handls Button1.Click
        Form2.Show()
        Me.Owner = Form2 'Form1 is the Name of Form Which will be Focused.
End Sub

I hope it will solve your problem.
 
Share this answer
 
'write the following code on the click event of button in form 1
Me.Hide()
        Form2.Show()
        Form2.StartPosition = FormStartPosition.CenterScreen


' write the following code on the Form2_LostFocus

 Me.Hide()
        Form1.ShowDialog()
        Form1.TopMost = True

enjoy
Sarfaraz
 
Share this answer
 
v2
Comments
RaviRanjanKr 20-Nov-11 9:52am    
A suggestion :- Always use "pre" tag to wrap your code to give it better readability to other users.
Manoj K Bhoir 20-Nov-11 10:06am    
Why you r hiding first form? In above question it is mentioned that both form should be visible but Second Form should be Focused.
There is no functional parent-child relationship between forms. However, one form is main, which is defined by the argument of Application.Run, also, you need to use different relationship, Owner/Owner form, see System.Windows.Forms.Form.Owner; it's the best to make all forms owned by the main form, which won't happen by default.

—SA
 
Share this answer
 
 
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