Results 1 to 5 of 5

Thread: MDI container question

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2005
    Posts
    150

    MDI container question

    hey,
    How do I get the child form to be "on top" of the parent form?.

    i.e the label on the parent form is appearing on top of the child form (see attached image), is there any code/property to change this?
    thanks
    Attached Images Attached Images  

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: MDI container question

    You can set the label's visible property to false befroe showing your child form. Then in the child form closing event, just set the visible property of the label on the parent form back to true.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2005
    Posts
    150

    Re: MDI container question

    yea I was thinking that,
    seems a bit of a round about way of fixing this issue tho, is there no other property of setting the child form to be on top?

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

    Re: MDI container question

    You need to understand how an MDI application works. When you set the IsMdiContainer property of a form to True it adds an MdiClient control to that form. The grey area you see in the client area of the form is that control. It's actually that control that hosts the child forms. That means that if you then add a control to the form it must either be in front of that MdiClient, which means it will obscure the MdiClient and any child forms it's hosting, or it must be behind it, which means it will be obscured itself. The only other option is to dock the control to an edge of the form so it will share the client area with the MdiClient. An MDI application is not intended to have controls over the child form area. If you really want text under the child forms, although I can't really see a good reason that you would, then your best option is to draw it directly on the MdiClient control, e.g.
    VB Code:
    1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.     For Each ctl As Control In Me.Controls
    3.         If TypeOf ctl Is MdiClient Then
    4.             AddHandler ctl.Paint, AddressOf MdiClient_Paint
    5.         End If
    6.     Next
    7. End Sub
    8.  
    9. Private Sub MdiClient_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs)
    10.     e.Graphics.DrawString("Token:", Me.Font, Brushes.Black, 25, 25)
    11. End Sub
    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
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: MDI container question

    Sorry, let's try that again in the correct language.
    Code:
    private void Form1_Load(object sender, EventArgs e)
    {
        foreach (Control ctl in this.Controls)
        {
            if (ctl is MdiClient)
            {
                ctl.Paint += new PaintEventHandler(MdiClient_Paint);
            }
        }
    }
    
    private void MdiClient_Paint(object sender, PaintEventArgs e)
    {
        e.Graphics.DrawString("Token:", this.Font, Brushes.Black, 25, 25);
    }
    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

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