This documentation is archived and is not being maintained.

Control.Anchor Property

Gets or sets which edges of the control are anchored to the edges of its container.

[Visual Basic]
Public Overridable Property Anchor As AnchorStyles
public virtual AnchorStyles Anchor {get; set;}
public: __property virtual AnchorStyles get_Anchor();
public: __property virtual void set_Anchor(AnchorStyles);
public function get Anchor() : AnchorStyles;
public function set Anchor(AnchorStyles);

Property Value

A bitwise combination of the AnchorStyles values. The default is Top and Left.


A control can be anchored to one or more edges of its parent container. Anchoring a control to its parent ensures that the anchored edges remain in the same position relative to the edges of the parent container when the parent container is resized. For example, if you have a Form with a Button whose Anchor property value is set to AnchorStyles.Top and AnchorStyles.Bottom, the Button is stretched to maintain the anchored distance to the top and bottom edges of the Form as the Height of the Form is increased.

For more information about anchoring and docking controls, see Walkthrough: Creating a Multipane User Interface with Windows Forms.

Notes to Inheritors:  When overriding the Anchor property in a derived class, use the base class's Anchor property to extend the base implementation. Otherwise, you must provide all the implementation. You are not required to override both the get and set accessors of the Anchor property; you can override only one if needed.


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

Control Class | Control Members | System.Windows.Forms Namespace | AnchorStyles | Dock | Layout