Results 1 to 9 of 9

Thread: Child forms.

  1. #1

    Thread Starter
    Hyperactive Member Ram2Curious's Avatar
    Join Date
    Apr 2010
    Posts
    484

    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....

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member Ram2Curious's Avatar
    Join Date
    Apr 2010
    Posts
    484

    Re: Child forms.

    Quote Originally Posted by jmcilhinney View Post
    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....

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Hyperactive Member Ram2Curious's Avatar
    Join Date
    Apr 2010
    Posts
    484

    Re: Child forms.

    I am currently using this code

    vb Code:
    1. Private Sub cmdProducts_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdProducts.Click
    2.  
    3.  
    4.  
    5.         Form1.MdiParent = Me
    6.         Form1.WindowState = FormWindowState.Maximized
    7.         Form1.Show()
    8.         Form1.BringToFront()
    9.  
    10.     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...

  6. #6
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7

  8. #8

    Thread Starter
    Hyperactive Member Ram2Curious's Avatar
    Join Date
    Apr 2010
    Posts
    484

    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....

  9. #9

    Thread Starter
    Hyperactive Member Ram2Curious's Avatar
    Join Date
    Apr 2010
    Posts
    484

    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
  •  



Click Here to Expand Forum to Full Width