locked
Docking inside a panel control RRS feed

  • Question

  • Hi,

    I have written a custom panel control in vb.net that adds 3D bevel effects to a standard panel. When I drag and drop a control onto my custom panel such as a text box or button and I then dock the text box or button, it docks to the outside dimensions of the panel covering the 3D bevels. How can I dock a control on the panel using the inside dimensions of the 3D bevels?


    Thanks,

    Scott
    Tuesday, March 16, 2010 7:32 PM

Answers

  • Hello,

    Use a tablelayoutpanel instead.

    Adam
    Dibble and dabble but please don't babble.
    • Marked as answer by Aland Li Wednesday, March 24, 2010 2:08 PM
    Tuesday, March 16, 2010 7:42 PM
  • Hi Scottwh1,

    There are two methods based on my experience:

    1. Adjust the Button/TextBox's Size and Location in designer to display it as you expected. Then set its Anchor property to 'Top, Bottom, Left, Right'.

    2. Replace the Panel with a TableLayoutPanel which has only one cell(one column,one row). Then place the Button/TextBox in the cell and set its Dock property to Fill. You can adjust the Button/TextBox's Margin property to display it as you expected.

    Regards,
    Aland Li


    Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
    • Marked as answer by Aland Li Wednesday, March 24, 2010 2:08 PM
    Friday, March 19, 2010 5:55 AM
  • Thanks for all of your input.

    With some direction from Microsoft, I was able to achieve the desired effect. This works like a charm.

    Private Sub CustomPanel_ControlAdded(ByVal sender As Object, ByVal e As System.Windows.Forms.ControlEventArgs) Handles Me.ControlAdded

    'Need to set the padding of the panel and not the padding of the             ‘control added to the panel. The Padding will create an inner ‘border for the ‘panel so that the add control docks within the ‘3D bevels.

                Me.Padding = New Padding(17)

                e.Control.Dock = Windows.Forms.DockStyle.Fill

            End Sub

     

     

    Thanks,

    Scott

     

     

     

    • Marked as answer by Scottwh1 Tuesday, April 6, 2010 6:36 PM
    Tuesday, April 6, 2010 6:36 PM

All replies

  • Hello,

    Use a tablelayoutpanel instead.

    Adam
    Dibble and dabble but please don't babble.
    • Marked as answer by Aland Li Wednesday, March 24, 2010 2:08 PM
    Tuesday, March 16, 2010 7:42 PM
  • Adam,

    Thanks for the reply. I need to be able to dock a control on the panel full so that it takes up the entire panel except for the bevel edges so that I can essentially frame a button or text box with the 3D look of the panel.

    Scott
    Tuesday, March 16, 2010 8:01 PM
  • Hi Scott,

    You will have to write your own docking algorithm based on the dimensions of the panel/control.

    This is my only thought.

    Adam
    Dibble and dabble but please don't babble.
    Tuesday, March 16, 2010 8:06 PM
  • Hi

    Here is an example of overriding the Client Rectangle, I did some testing with a panel and it does create some redraw issues.

    http://stackoverflow.com/questions/1725987/set-clientrectangle-in-custom-form-in-c

    Paul.
    Wednesday, March 17, 2010 1:18 PM
  • Hi Scottwh1,

    There are two methods based on my experience:

    1. Adjust the Button/TextBox's Size and Location in designer to display it as you expected. Then set its Anchor property to 'Top, Bottom, Left, Right'.

    2. Replace the Panel with a TableLayoutPanel which has only one cell(one column,one row). Then place the Button/TextBox in the cell and set its Dock property to Fill. You can adjust the Button/TextBox's Margin property to display it as you expected.

    Regards,
    Aland Li


    Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
    • Marked as answer by Aland Li Wednesday, March 24, 2010 2:08 PM
    Friday, March 19, 2010 5:55 AM
  • Thanks for all of your input.

    With some direction from Microsoft, I was able to achieve the desired effect. This works like a charm.

    Private Sub CustomPanel_ControlAdded(ByVal sender As Object, ByVal e As System.Windows.Forms.ControlEventArgs) Handles Me.ControlAdded

    'Need to set the padding of the panel and not the padding of the             ‘control added to the panel. The Padding will create an inner ‘border for the ‘panel so that the add control docks within the ‘3D bevels.

                Me.Padding = New Padding(17)

                e.Control.Dock = Windows.Forms.DockStyle.Fill

            End Sub

     

     

    Thanks,

    Scott

     

     

     

    Tuesday, April 6, 2010 6:36 PM
  • Thanks for all of your input.

    With some direction from Microsoft, I was able to achieve the desired effect. This works like a charm.

    Private Sub CustomPanel_ControlAdded(ByVal sender As Object, ByVal e As System.Windows.Forms.ControlEventArgs) Handles Me.ControlAdded

    'Need to set the padding of the panel and not the padding of the             ‘control added to the panel. The Padding will create an inner ‘border for the ‘panel so that the add control docks within the ‘3D bevels.

                Me.Padding = New Padding(17)

                e.Control.Dock = Windows.Forms.DockStyle.Fill

            End Sub

     

     

    Thanks,

    Scott

     

     

     

    • Marked as answer by Scottwh1 Tuesday, April 6, 2010 6:36 PM
    Tuesday, April 6, 2010 6:36 PM