Results 1 to 3 of 3

Thread: Dock to centre?

  1. #1

    Thread Starter
    New Member Strider96's Avatar
    Join Date
    Nov 2009
    Posts
    7

    Dock to centre?

    Well, I created a program in VB 2010 but I have a problem, I want to dock a control on the program to the centre but the only options for docking are:
    Top
    Left
    Bottom
    Right
    Fill
    None

    So? What do I do?

  2. #2
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: Dock to centre?

    You have two options, depending on the rest of your layout.

    1. You can use dockstyle Fill and use the Padding property (of the container) to define a margin between the border and the control. In case there are other controls, this usually doesn't work too well as they will be influenced by the Padding of their container as well.

    2. Use the Anchor property to anchor it to all sides.


    EDIT
    Both of those methods will resize the control if its container is resized. If that is not what you want, then I'm not sure if it's possible without code. You can always handle the containers Resize event and calculate the desired position of the control there.

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

    Re: Dock to centre?

    If you want the control to stay in the middle of the form then it's not really docking. A ship doesn't dock in the middle of the ocean. Docking implies being adjacent to something. In the case of controls, they are docked to one or all sides of their container.

    If you want a control to stay in the middle of a form and not get resized then you pretty much have two choices:

    1. Add a TableLayoutPanel with three rows and three columns. Make the middle row and column auto-size so they will fit your control exactly, then make the other rows and columns 50% each. As the form resizes the TLP will expand and contract the outer rows and columns equally while keeping the middle row and column auto-sized to your control.

    2. Handle the SizeChanged event of your form and manually calculate the new Location for the control. It's a pretty simple calculation based on the Height and Width of the form and the control.
    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