|
-
Feb 15th, 2011, 11:14 AM
#1
Thread Starter
Hyperactive Member
Child forms.
Hi,
I am developing a small application using VS2008, the mdiparent has a expandable panel with Button 1 and Button 2 on it, which opens up child form 1 and child form 2. ( The two child forms are maximized within the mdiparent form)
The problem is, button 1 opens child form 1 and button 2 - child form 2. I cant open the two forms randomly. I have to close the topmost form to access the other forms below it and vice versa.
Can anybody please help me out with the random opening of child forms.....?
Please help me....
Thank you....
-
Feb 15th, 2011, 05:48 PM
#2
Re: Child forms.
I would think that you can open the two forms randomly. Maybe you just have an issue with the form you just opened being covered by the other, but that doesn't mean that it's not open. My first suggestion would be to call Activate on the form you just opened. If that doesn't work, assign it to the parent's ActiveMdiChild property. If that doesn't work, try calling its BringToFront method. If that doesn't work, post back and show us the relevant code.
-
Feb 15th, 2011, 10:53 PM
#3
Thread Starter
Hyperactive Member
Re: Child forms.
 Originally Posted by jmcilhinney
I would think that you can open the two forms randomly. Maybe you just have an issue with the form you just opened being covered by the other, but that doesn't mean that it's not open. My first suggestion would be to call Activate on the form you just opened. If that doesn't work, assign it to the parent's ActiveMdiChild property. If that doesn't work, try calling its BringToFront method. If that doesn't work, post back and show us the relevant code.
All your suggested methods are working properly, thanks, but i have a problem with the speed the forms are displayed. For example, if i am using the code as below
Code:
Private Sub cmdDosage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDosage.Click
Form3.BringToFront()
Form3.MdiParent = Me
Form3.Show()
End Sub
and for Form3 to maximize on Form3, form load
Code:
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.WindowState = FormWindowState.Maximized
End Sub
Once the button is clicked, Form3 opens up with the frame appearing around it for a second and then it is maximized.... How to avoid this and display the form smoothly....
Please help me out....
Thank you....
-
Feb 15th, 2011, 11:03 PM
#4
Re: Child forms.
You should not be calling BringToFront first. If the form isn't displayed then you can't bring it to the front. The BringToFront call should be last.
Don't maximise the form in code. Set the WindowState property to Maximized in the designer. Alternatively, set it in code in the parent window BEFORE calling Show.
-
Feb 16th, 2011, 07:43 AM
#5
Thread Starter
Hyperactive Member
Re: Child forms.
I am currently using this code
vb Code:
Private Sub cmdProducts_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdProducts.Click Form1.MdiParent = Me Form1.WindowState = FormWindowState.Maximized Form1.Show() Form1.BringToFront() End Sub
But still the window frame of child Form 1 appears before it is completely maximized in the mdiparent form. I tried many different ways including setting the FormBorderStyle to ' None ' but still the frame appears.... How to make the child form to be displayed smooth and quick...?
And i am using DotNetBar 9.0 in my application....Is it because of this the child forms are slowing down..?
Kindly help me....
Thanks...
-
Feb 16th, 2011, 09:08 AM
#6
Re: Child forms.
Let's see.... how do I put this... I suspect that this is a case of default instances being used...Ram, I realize that probably didn't mean anything to you, but I know jmc knows what I'm talking about.
Ram2 - jsut for S&G's try this... at the top of your MDI form, add a new variable... call it chilfRom1 and dim it as type Form1 and set it to Nothing:
Code:
Private childForm1 As Form1 = Nothing
Comment out your existing code for now:
Code:
Private Sub cmdProducts_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdProducts.Click
'Form1.MdiParent = Me
'Form1.WindowState = FormWindowState.Maximized
'Form1.Show()
'Form1.BringToFront()
End Sub
And then change it like so:
Code:
Private Sub cmdProducts_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdProducts.Click
'Form1.MdiParent = Me
'Form1.WindowState = FormWindowState.Maximized
'Form1.Show()
'Form1.BringToFront()
If childForm1 Is Nothing Then
childForm1 = New Form1
childForm1.MdiParent = Me
childForm1.WindowState = FormWindowState.Maximized
End If
childForm.Show()
childForm.BringToFront()
End Sub
See if that makes any difference...
-tg
-
Feb 16th, 2011, 09:10 AM
#7
Re: Child forms.
What other tasks are you running in the Load event of the child form? This can sometimes cause it to slow down.
-
Feb 17th, 2011, 02:39 AM
#8
Thread Starter
Hyperactive Member
Re: Child forms.
But still even after trying the codes by tg,the frames appear before maximizing...
I got this code from Microsoft Support website and which is working perfectly....
Code:
Private Sub cmdProducts_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdProducts.Click
Dim frm As Form1
frm = New Form1
frm.MdiParent = Me
frm.WindowState = FormWindowState.Maximized
frm.Show()
End Sub
But the child form appears as many times the button is clicked, with 2 clicks the form appears twice in z-order, ie. one above the other.
Please help me in correcting the codes......
Thank you....
-
Feb 17th, 2011, 08:31 AM
#9
Thread Starter
Hyperactive Member
Re: Child forms.
Hi tg,
I tried your code, but the form opens only once. When i close it and try to open it again then it does not open and another problem is that the form is not maximized completely even after a workaround with designer settings and codes.....
What might be the problem...? Is it a kind of bug in VS 2008...?
Should i leave this type of child form system and jump on to using TabControl....?
Kindly help.....
Last edited by Ram2Curious; Feb 17th, 2011 at 09:44 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|