Resizing an MDI child withim the MDIParent.

Discussion in 'Microsoft Dot NET Framework Forms' started by Guest, Dec 20, 2005.

  1. Guest

    Guest Guest

    Hi. I have been trying unsuccessfully to resize an MDI child form to fit
    exactly into the MDIParent and cover the whole of the ClientRectangle.
    All code that I have written using the ClientRectangle shows the child form
    as a bit to big and the MDI displayes scroll bars. .ClientSize.Width and
    ..ClientSize.height seem to return larger values than the Client area really
    is.
    Docking, which does give the correct result. is not an alternative as the
    displayed child form cannot then be manipulated by the user to other
    positions in the MDI client area.

    Help would be appreciated.
     
    Guest, Dec 20, 2005
    #1
    1. Advertisements

  2. Guest

    Fox Guest

    Did you try to maximise your child form?


    "Amnon Rapoport" <> wrote in message
    news:...
    > Hi. I have been trying unsuccessfully to resize an MDI child form to fit
    > exactly into the MDIParent and cover the whole of the ClientRectangle.
    > All code that I have written using the ClientRectangle shows the child
    > form
    > as a bit to big and the MDI displayes scroll bars. .ClientSize.Width and
    > .ClientSize.height seem to return larger values than the Client area
    > really
    > is.
    > Docking, which does give the correct result. is not an alternative as the
    > displayed child form cannot then be manipulated by the user to other
    > positions in the MDI client area.
    >
    > Help would be appreciated.
     
    Fox, Dec 20, 2005
    #2
    1. Advertisements

  3. As well as Fox's recommendation you should also remember that the main form
    is not actually the parent of the MDI child form. This role is undertaken by
    the MDIClient which is owned by the main form. You should use this control
    to provide information on main form areas etc.

    There is an article in Windows Forms Tips and Tricks that explains how to
    put a background on the MDIClient. This will show you how to obtain a
    reference to that object.

    --
    Bob Powell [MVP]
    Visual C#, System.Drawing

    Ramuseco Limited .NET consulting
    http://www.ramuseco.com

    Find great Windows Forms articles in Windows Forms Tips and Tricks
    http://www.bobpowell.net/tipstricks.htm

    Answer those GDI+ questions with the GDI+ FAQ
    http://www.bobpowell.net/faqmain.htm

    All new articles provide code in C# and VB.NET.
    Subscribe to the RSS feeds provided and never miss a new article.





    "Amnon Rapoport" <> wrote in message
    news:...
    > Hi. I have been trying unsuccessfully to resize an MDI child form to fit
    > exactly into the MDIParent and cover the whole of the ClientRectangle.
    > All code that I have written using the ClientRectangle shows the child
    > form
    > as a bit to big and the MDI displayes scroll bars. .ClientSize.Width and
    > .ClientSize.height seem to return larger values than the Client area
    > really
    > is.
    > Docking, which does give the correct result. is not an alternative as the
    > displayed child form cannot then be manipulated by the user to other
    > positions in the MDI client area.
    >
    > Help would be appreciated.
     
    Bob Powell [MVP], Dec 20, 2005
    #3
  4. Guest

    Amnon Guest

    Well, maximizing would be very much like using the Docking property.

    The user would not be able to move the MDIChild around in the client area.

    In VB6, the code is so trivial and it is causing me so much work in VS2005.

    Very disheartening

    Amnon


    "Fox" <> wrote in message
    news:...
    > Did you try to maximise your child form?
    >
    >
    > "Amnon Rapoport" <> wrote in
    > message news:...
    >> Hi. I have been trying unsuccessfully to resize an MDI child form to fit
    >> exactly into the MDIParent and cover the whole of the ClientRectangle.
    >> All code that I have written using the ClientRectangle shows the child
    >> form
    >> as a bit to big and the MDI displayes scroll bars. .ClientSize.Width and
    >> .ClientSize.height seem to return larger values than the Client area
    >> really
    >> is.
    >> Docking, which does give the correct result. is not an alternative as the
    >> displayed child form cannot then be manipulated by the user to other
    >> positions in the MDI client area.
    >>
    >> Help would be appreciated.

    >
    >
     
    Amnon, Dec 20, 2005
    #4
  5. Guest

    Amnon Guest

    Well thank you Bob.

    The whole MDI child resizing stuff has become a real nightmare.

    I implemented parts of your code to get the right result ONCE. Then, if I
    regenerated the same MDI child form, it seems that hidden mechanisms force
    the second MDI client to be 'cascaded' relative to the visible 'child area'
    of the MDI form. Do I have to look in the controls collection for the first
    MDIClient by searching for its handle.

    Then, what happens when I want a second different MDIChild form to be
    generated. One on top of the other - not maximised and not 'docked'

    How do I cancel the seeming default mechanism of the MDIParent to cascade
    all subsequent instances IF this is indeed what is happening.

    What a nightmare.

    I would perhaps suggest that Microsoft does not want developers to use MDI
    projects. Or at least in the way we used them in VB6.

    I include the following code:

    Public Function ReturnMDIClient(ByVal frm As System.Windows.Forms.Form) As
    System.Windows.Forms.Control
    Dim c As Control
    For Each c In frm.Controls
    If TypeOf c Is MdiClient Then
    ReturnMDIClient = c
    End If
    Next c

    End Function

    AND

    Dim frmBrowse As New Form1
    Dim MDIClient As System.Windows.Forms.Control

    MDIClient = ReturnMDIClient(frmMain)
    frmBrowse.MdiParent = frmMain
    frmBrowse.Left = 0 'MDIClient.Left
    frmBrowse.Top = 0 'MDIClient.Top
    frmBrowse.Width = MDIClient.Width - 5
    frmBrowse.Height = MDIClient.Height - 5
    frmBrowse.Show()

    The first time that the MDIChild was generated, it fitted nicely into the
    client area but the second time with the same instance of the frmMain, the
    ..top and .left values were displaced as if it were cascaded relative to the
    first.

    I tried to send this email with a screen shot of the cascading effect BUT
    there was an error

    Awaiting your comments

    Amnon

    "Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
    news:...
    > As well as Fox's recommendation you should also remember that the main
    > form
    > is not actually the parent of the MDI child form. This role is undertaken
    > by
    > the MDIClient which is owned by the main form. You should use this control
    > to provide information on main form areas etc.
    >
    > There is an article in Windows Forms Tips and Tricks that explains how to
    > put a background on the MDIClient. This will show you how to obtain a
    > reference to that object.
    >
    > --
    > Bob Powell [MVP]
    > Visual C#, System.Drawing
    >
    > Ramuseco Limited .NET consulting
    > http://www.ramuseco.com
    >
    > Find great Windows Forms articles in Windows Forms Tips and Tricks
    > http://www.bobpowell.net/tipstricks.htm
    >
    > Answer those GDI+ questions with the GDI+ FAQ
    > http://www.bobpowell.net/faqmain.htm
    >
    > All new articles provide code in C# and VB.NET.
    > Subscribe to the RSS feeds provided and never miss a new article.
    >
    >
    >
    >
    >
    > "Amnon Rapoport" <> wrote in
    > message
    > news:...
    >> Hi. I have been trying unsuccessfully to resize an MDI child form to fit
    >> exactly into the MDIParent and cover the whole of the ClientRectangle.
    >> All code that I have written using the ClientRectangle shows the child
    >> form
    >> as a bit to big and the MDI displayes scroll bars. .ClientSize.Width and
    >> .ClientSize.height seem to return larger values than the Client area
    >> really
    >> is.
    >> Docking, which does give the correct result. is not an alternative as the
    >> displayed child form cannot then be manipulated by the user to other
    >> positions in the MDI client area.
    >>
    >> Help would be appreciated.

    >
    >
     
    Amnon, Dec 20, 2005
    #5
  6. "Amnon" <> wrote in message
    news:OaLLh$...
    > Well thank you Bob.
    >
    > The first time that the MDIChild was generated, it fitted nicely into the
    > client area but the second time with the same instance of the frmMain, the
    > .top and .left values were displaced as if it were cascaded relative to
    > the
    > first.


    Try setting the MDIChild's StartPosition to manual.
     
    Martin Stainsby, Dec 20, 2005
    #6
  7. Guest

    Amnon Guest

    Thank you Martin.

    That did the job

    Amnon


    "Martin Stainsby" <> wrote in message
    news:%...
    >
    > "Amnon" <> wrote in message
    > news:OaLLh$...
    >> Well thank you Bob.
    >>
    >> The first time that the MDIChild was generated, it fitted nicely into the
    >> client area but the second time with the same instance of the frmMain,
    >> the
    >> .top and .left values were displaced as if it were cascaded relative to
    >> the
    >> first.

    >
    > Try setting the MDIChild's StartPosition to manual.
    >
    >
     
    Amnon, Dec 21, 2005
    #7
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marina Neyman

    MDI - how to open a child from a child within MDI parent form?

    Marina Neyman, Feb 7, 2004, in forum: Microsoft Dot NET Framework Forms
    Replies:
    0
    Views:
    902
    Marina Neyman
    Feb 7, 2004
  2. Marina Neyman

    MDI - how to open a child from a child within MDI parent?

    Marina Neyman, Feb 7, 2004, in forum: Microsoft Dot NET Framework Forms
    Replies:
    1
    Views:
    617
    Bernie Yaeger
    Feb 7, 2004
  3. kstuver
    Replies:
    1
    Views:
    700
    Michael Höhne
    Dec 12, 2005
  4. Earl

    Calling a method in one MDI child from another MDI child

    Earl, Dec 20, 2006, in forum: Microsoft Dot NET Framework Forms
    Replies:
    5
    Views:
    358
  5. Jenbo

    Opening MDI Child From MDI Child Form, like VisStudio Start Page

    Jenbo, Mar 1, 2007, in forum: Microsoft Dot NET Framework Forms
    Replies:
    1
    Views:
    520
    Bryan Phillips
    Mar 7, 2007
Loading...

Share This Page