Resize nested control at runtime

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Russ Green

    Resize nested control at runtime

    I have a VB.NET app that uses lots of forms which I am loading into a panel
    cotrol using.....

    Me.pnlMain.Cont rols.Clear()

    frm.TopLevel = False
    frm.WindowState = FormWindowState .Maximized
    frm.Dock = DockStyle.Fill
    frm.Anchor = AnchorStyles.Le ft + AnchorStyles.Ri ght + AnchorStyles.To p +
    AnchorStyles.Bo ttom
    frm.AutoSize = True
    frm.AutoSizeMod e = Windows.Forms.A utoSizeMode.Gro wAndShrink

    Me.pnlMain.Cont rols.Add(frm)
    frm.Show()


    What I want to do though is have the form resize when the panel control
    (which resizes with it's main form) resizes....i've tried something like the
    following but it's not working....How can I do this?

    Private Sub pnlMain_Resize( ByVal sender As Object, ByVal e As
    System.EventArg s) Handles pnlMain.Resize
    On Error Resume Next
    Debug.WriteLine (Me.pnlMain.Siz e.Width.ToStrin g & " x " &
    Me.pnlMain.Size .Height.ToStrin g)
    Debug.WriteLine (Me.pnlMain.Con trols.Item(0).W idth & " x " &
    Me.pnlMain.Cont rols.Item(0).He ight)

    Dim oFrm As New Form

    If Me.pnlMain.Cont rols.Count 0 Then
    'Debug.WriteLin e("There is a control in the panel " &
    Me.pnlMain.Cont rols.Item(0).Na me)
    With Me.pnlMain.Cont rols.Item(0)
    .Size = New Size(Me.pnlMain .Size.Width,
    Me.pnlMain.Size .Height)
    End With


    End If
    End Sub



  • Branco Medeiros

    #2
    Re: Resize nested control at runtime

    Russ Green wrote:
    I have a VB.NET app that uses lots of forms which I am loading into a panel
    cotrol using.....
    >
    Me.pnlMain.Cont rols.Clear()
    >
    frm.TopLevel = False
    frm.WindowState = FormWindowState .Maximized
    frm.Dock = DockStyle.Fill
    frm.Anchor = AnchorStyles.Le ft + AnchorStyles.Ri ght + AnchorStyles.To p +
    AnchorStyles.Bo ttom
    frm.AutoSize = True
    frm.AutoSizeMod e = Windows.Forms.A utoSizeMode.Gro wAndShrink
    >
    Me.pnlMain.Cont rols.Add(frm)
    frm.Show()
    >
    What I want to do though is have the form resize when the panel control
    (which resizes with it's main form) resizes....i've tried something like the
    following but it's not working....How can I do this?
    <snip>

    You're doing too much. You only need to set TopLevel to false, Dock to
    Fill and add the form to the panel. The other properties (WindowState,
    Autosize, etc) are not needed. Setting WindowState will actually
    prevent the form from automatically resizing.

    HTH.

    Regards,

    Branco.

    Comment

    • Russ Green

      #3
      Re: Resize nested control at runtime

      Thanks for the reply but I've now only got

      Me.pnlMain.Cont rols.Clear()

      frm.TopLevel = False
      frm.Dock = DockStyle.Fill

      Me.pnlMain.Cont rols.Add(frm)
      frm.Show()

      And when my panel resizes the form I've loaded into it doesn't.


      Comment

      • Branco Medeiros

        #4
        Re: Resize nested control at runtime

        Russ Green wrote:
        Thanks for the reply but I've now only got
        >
        Me.pnlMain.Cont rols.Clear()
        >
        frm.TopLevel = False
        frm.Dock = DockStyle.Fill
        >
        Me.pnlMain.Cont rols.Add(frm)
        frm.Show()
        >
        And when my panel resizes the form I've loaded into it doesn't.
        Maybe you need to provide more details, then (are you setting some of
        those properties in the designer, for instance?).

        It resizes here... =)

        Regards,

        Branco.

        Comment

        • Russ Green

          #5
          Re: Resize nested control at runtime

          Yes, some of the other properties are set in the designer....fou nd them
          and fixed it.....troubled me for ages....thanks


          Comment

          Working...