Results 1 to 7 of 7

Thread: [RESOLVED] mdiparent control

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2005
    Posts
    30

    Resolved [RESOLVED] mdiparent control

    When i add a control on a mdiparent form for example a label control.
    The label stands for the mdi child. How is possible to bring mdi child on the foreground? When i try this code
    Code:
    label.SendToBack();
    It doesn't appears anymore.
    Anyone did solved this problem?

    Thanks by advance

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

    Re: mdiparent control

    I'm confused as to what you actually want to accomplish. If you want the user to be able to click something to activate each child form then you should add a MenuStrip and assign one of its menu items to its MdiWindowListItem property. You'd usually use a menu item named "Window". If you do that a menu item will automatically be added for each MDI child window.
    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
    Junior Member
    Join Date
    Aug 2005
    Posts
    30

    Re: mdiparent control

    I think i couldn't explain my problem. Here i added a picture of my problem.

    Thaks for reply
    Attached Images Attached Images  

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

    Re: mdiparent control

    OK, I get it now. When you set the IsMdiContainer property of a form to True what actually happens is that an MdiClient control is added to your form. That's what the grey area is that you see covering the form and it's that control that acts as the host for the child forms.

    Now, when you add a Label to your parent form it is added over the MdiClient control. That means that it is also over the top of any child forms that that MdiClient control is hosting. It's simply not possible to do what you want in the designer. There is no way to access that MdiClient control in the designer to place controls on it directly. In fact, there's no way to place controls on it in code either because it is designed to host forms only.

    If you want text on your MdiClient then you need to use GDI+ to put it there:
    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.             Exit For
    6.         End If
    7.     Next ctl
    8. End Sub
    9.  
    10. Private Sub MdiClient_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs)
    11.     'Draw text directly on the MdiClient.
    12.     e.Graphics.DrawString("This text can be covered by child windows.", _
    13.                           Me.Font, _
    14.                           Brushes.Black, _
    15.                           100, _
    16.                           100)
    17. 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: mdiparent control

    Bah! Did it again. I keep getting to subscribed threads via my UserCP and not realising that they're in the C# forum. Here's the equivalent C# code:
    C# Code:
    1. private void Form1_Load(object sender, EventArgs e)
    2. {
    3.     foreach (Control ctl in this.Controls)
    4.     {
    5.         if (ctl is MdiClient)
    6.         {
    7.             ctl.Paint += new PaintEventHandler(MdiClient_Paint);
    8.             break;
    9.         }
    10.     }
    11. }
    12.  
    13. private void MdiClient_Paint(object sender, PaintEventArgs e)
    14. {
    15.     e.Graphics.DrawString("This text can be covered by child windows.",
    16.                           this.Font,
    17.                           Brushes.Black,
    18.                           100,
    19.                           100);
    20. }
    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

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Aug 2005
    Posts
    30

    Re: mdiparent control

    This code working perfect but now how can i change the x, y coordinate of the label when for example form is resizing ?

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Aug 2005
    Posts
    30

    Re: mdiparent control

    Ok i found it. It's just same as before. Sorry for last post and thanks a lot for helpinggggg
    )
    Code:
    int x = (this.Width / 2) - (lblAllText.Width / 2);
    int y = this.Height-166;
    
    e.Graphics.DrawString(lblAll.Text, lblAll.Font, Brushes.Black, x,y);

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