Quantcast
Channel: AuthorCode » Windows Controls
Viewing all articles
Browse latest Browse all 10

Dock property of control in c#

$
0
0

 
You can set the control borders to docked to its parent control through Dock property. Dock property of any control determines how a control is resized with its parent control.means how a control automatically resized as its parent control is resized. for example if you set the dock property of a control to Left, then it automatically align with the left side of its parent and it will automatically resize as the parent control is resized.

Dock property

Dock Locations

There is one point to need consider here that Anchor and Dock properties are mutually exclusive. Only one can be set at a time and the last one set takes precedence.

Example

The following c# example creates a Panel and sets some of its common properties and then set the Dock property of this to Top.
and then set the Dock property of this to Top.

  1. private void CreatePanelAndSetDock()
  2. {
  3.  Panel Pnl = new Panel();
  4.  Pnl.BackColor = Color.Gray;
  5.  Pnl.Height = 50;
  6.  Pnl.BorderStyle = BorderStyle.Fixed3D;
  7.  this.Controls.Add(Pnl);
  8.  Pnl.Dock = DockStyle.Top;
  9. }

Viewing all articles
Browse latest Browse all 10

Trending Articles