Shape.Anchor Property
Gets or sets the edges of the container to which a shape is bound, and determines how a shape is resized when its parent is resized.
Namespace: Microsoft.VisualBasic.PowerPacks
Assembly: Microsoft.VisualBasic.PowerPacks.Vs (in Microsoft.VisualBasic.PowerPacks.Vs.dll)
Syntax
'宣告
Public Overridable Property Anchor As AnchorStyles
Get
Set
public virtual AnchorStyles Anchor { get; set; }
public:
virtual property AnchorStyles Anchor {
AnchorStyles get ();
void set (AnchorStyles value);
}
abstract Anchor : AnchorStyles with get, set
override Anchor : AnchorStyles with get, set
function get Anchor () : AnchorStyles
function set Anchor (value : AnchorStyles)
Property Value
Type: System.Windows.Forms.AnchorStyles
A bitwise combination of the AnchorStyles values. The default is Top and Left.
Remarks
Use the Anchor property to define how a shape is automatically resized when its parent control is resized. Anchoring a shape to its parent control guarantees that the anchored edges remain in the same position relative to the edges of the parent control when the parent control is resized.
You can anchor a shape to one or more edges of its container. For example, assume that you have a Form that contains a RectangleShape whose Anchor property value is set to Top and Bottom. The RectangleShape is stretched to maintain the distance between the top and bottom edges of the Form as the Height of the Form is increased.
Notes to Inheritors
When you override 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 you need to.
Examples
The following example shows how to use the Anchor property to resize shapes when a form is resized. This example requires that you have two or more shape or line controls on a form.
Private Sub ResizeShapes()
' Loop through the ShapeCollection.
For Each shape As PowerPacks.Shape In ShapeContainer1.Shapes
' Set the Anchor property.
shape.Anchor = AnchorStyles.Bottom Or AnchorStyles.Left Or
AnchorStyles.Right Or AnchorStyles.Top
Next
End Sub
private void ResizeShapes()
{
// Loop through the ShapeCollection.
foreach (Shape shape in shapeContainer1.Shapes)
{
// Set the Anchor property.
shape.Anchor = AnchorStyles.Bottom | AnchorStyles.Left |
AnchorStyles.Right | AnchorStyles.Top;
}
}
.NET Framework Security
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.
See Also
Reference
Microsoft.VisualBasic.PowerPacks Namespace
Other Resources
How to: Draw Lines with the LineShape Control (Visual Studio)
How to: Draw Shapes with the OvalShape and RectangleShape Controls (Visual Studio)