ShapeContainer Class
Provides a container for LineShape, OvalShape, RectangleShape controls, and for any other control that derives from Shape.
Namespace: Microsoft.VisualBasic.PowerPacks
Assembly: Microsoft.VisualBasic.PowerPacks.Vs (in Microsoft.VisualBasic.PowerPacks.Vs.dll)
Inheritance Hierarchy
System.Object
System.MarshalByRefObject
System.ComponentModel.Component
System.Windows.Forms.Control
System.Windows.Forms.ScrollableControl
System.Windows.Forms.ContainerControl
System.Windows.Forms.UserControl
Microsoft.VisualBasic.PowerPacks.ShapeContainer
Syntax
[BrowsableAttribute(false)]
public sealed class ShapeContainer : UserControl
[BrowsableAttribute(false)]
public ref class ShapeContainer sealed : UserControl
[<Sealed>]
[<BrowsableAttribute(false)>]
type ShapeContainer =
class
inherit UserControl
end
<BrowsableAttribute(False)>
Public NotInheritable Class ShapeContainer
Inherits UserControl
Constructors
Name | Description | |
---|---|---|
ShapeContainer() | Initializes a new instance of the ShapeContainer class. |
Properties
Name | Description | |
---|---|---|
AccessibilityObject | (Inherited from Control.) |
|
AccessibleDefaultActionDescription | (Inherited from Control.) |
|
AccessibleDescription | (Inherited from Control.) |
|
AccessibleName | (Inherited from Control.) |
|
AccessibleRole | Gets or sets the accessible role of the ShapeContainer. |
|
ActiveControl | (Inherited from ContainerControl.) |
|
AllowDrop | (Inherited from Control.) |
|
Anchor | (Inherited from Control.) |
|
AutoScaleDimensions | (Inherited from ContainerControl.) |
|
AutoScaleMode | (Inherited from ContainerControl.) |
|
AutoScroll | (Inherited from ScrollableControl.) |
|
AutoScrollMargin | (Inherited from ScrollableControl.) |
|
AutoScrollMinSize | (Inherited from ScrollableControl.) |
|
AutoScrollOffset | (Inherited from Control.) |
|
AutoScrollPosition | (Inherited from ScrollableControl.) |
|
AutoSize | (Inherited from UserControl.) |
|
AutoSizeMode | (Inherited from UserControl.) |
|
AutoValidate | (Inherited from UserControl.) |
|
BackColor | (Inherited from Control.) |
|
BackgroundImage | (Inherited from Control.) |
|
BackgroundImageLayout | (Inherited from Control.) |
|
BindingContext | (Inherited from ContainerControl.) |
|
BorderStyle | (Inherited from UserControl.) |
|
Bottom | (Inherited from Control.) |
|
Bounds | (Inherited from Control.) |
|
CanFocus | (Inherited from Control.) |
|
CanSelect | (Inherited from Control.) |
|
Capture | (Inherited from Control.) |
|
CausesValidation | (Inherited from Control.) |
|
ClientRectangle | (Inherited from Control.) |
|
ClientSize | (Inherited from Control.) |
|
CompanyName | (Inherited from Control.) |
|
Container | (Inherited from Component.) |
|
ContainsFocus | (Inherited from Control.) |
|
ContextMenu | (Inherited from Control.) |
|
ContextMenuStrip | (Inherited from Control.) |
|
Controls | (Inherited from Control.) |
|
Created | (Inherited from Control.) |
|
CurrentAutoScaleDimensions | (Inherited from ContainerControl.) |
|
Cursor | Gets or sets the cursor that is displayed when the mouse pointer is over a ShapeContainer.(Overrides Control.Cursor.) |
|
DataBindings | (Inherited from Control.) |
|
DisplayRectangle | (Inherited from ScrollableControl.) |
|
Disposing | (Inherited from Control.) |
|
Dock | Gets or sets which control borders are docked to the parent control and determines how a control is resized when its parent is resized.(Overrides Control.Dock.) |
|
Enabled | (Inherited from Control.) |
|
Focused | (Inherited from Control.) |
|
Font | (Inherited from Control.) |
|
ForeColor | (Inherited from Control.) |
|
Handle | (Inherited from Control.) |
|
HasChildren | (Inherited from Control.) |
|
Height | (Inherited from Control.) |
|
HorizontalScroll | (Inherited from ScrollableControl.) |
|
ImeMode | (Inherited from Control.) |
|
InvokeRequired | (Inherited from Control.) |
|
IsAccessible | (Inherited from Control.) |
|
IsDisposed | (Inherited from Control.) |
|
IsHandleCreated | (Inherited from Control.) |
|
IsMirrored | (Inherited from Control.) |
|
LayoutEngine | (Inherited from Control.) |
|
Left | (Inherited from Control.) |
|
Location | (Inherited from Control.) |
|
Margin | (Inherited from Control.) |
|
MaximumSize | (Inherited from Control.) |
|
MinimumSize | (Inherited from Control.) |
|
Name | (Inherited from Control.) |
|
Padding | (Inherited from Control.) |
|
Parent | (Inherited from Control.) |
|
ParentForm | (Inherited from ContainerControl.) |
|
PreferredSize | (Inherited from Control.) |
|
ProductName | (Inherited from Control.) |
|
ProductVersion | (Inherited from Control.) |
|
RecreatingHandle | (Inherited from Control.) |
|
Region | (Inherited from Control.) |
|
RenderRightToLeft | (Inherited from Control.) |
|
Right | (Inherited from Control.) |
|
RightToLeft | (Inherited from Control.) |
|
Shapes | Gets the collection of shapes that are contained in the ShapeContainer. |
|
ShowFocusCues | (Inherited from Control.) |
|
ShowKeyboardCues | (Inherited from Control.) |
|
Site | (Inherited from Control.) |
|
Size | (Inherited from Control.) |
|
TabIndex | (Inherited from Control.) |
|
TabStop | (Inherited from Control.) |
|
Tag | (Inherited from Control.) |
|
Text | (Inherited from Control.) |
|
Top | (Inherited from Control.) |
|
TopLevelControl | (Inherited from Control.) |
|
UseWaitCursor | (Inherited from Control.) |
|
VerticalScroll | (Inherited from ScrollableControl.) |
|
Visible | (Inherited from Control.) |
|
Width | (Inherited from Control.) |
Methods
Events
Name | Description | |
---|---|---|
AutoSizeChanged | (Inherited from UserControl.) |
|
AutoValidateChanged | (Inherited from UserControl.) |
|
BackColorChanged | (Inherited from Control.) |
|
BackgroundImageChanged | (Inherited from Control.) |
|
BackgroundImageLayoutChanged | (Inherited from Control.) |
|
BindingContextChanged | (Inherited from Control.) |
|
CausesValidationChanged | (Inherited from Control.) |
|
ChangeUICues | (Inherited from Control.) |
|
Click | (Inherited from Control.) |
|
ClientSizeChanged | (Inherited from Control.) |
|
ContextMenuChanged | (Inherited from Control.) |
|
ContextMenuStripChanged | (Inherited from Control.) |
|
ControlAdded | (Inherited from Control.) |
|
ControlRemoved | (Inherited from Control.) |
|
CursorChanged | (Inherited from Control.) |
|
Disposed | (Inherited from Component.) |
|
DockChanged | (Inherited from Control.) |
|
DoubleClick | (Inherited from Control.) |
|
DragDrop | (Inherited from Control.) |
|
DragEnter | (Inherited from Control.) |
|
DragLeave | (Inherited from Control.) |
|
DragOver | (Inherited from Control.) |
|
EnabledChanged | (Inherited from Control.) |
|
Enter | (Inherited from Control.) |
|
FontChanged | (Inherited from Control.) |
|
ForeColorChanged | (Inherited from Control.) |
|
GiveFeedback | (Inherited from Control.) |
|
GotFocus | (Inherited from Control.) |
|
HandleCreated | (Inherited from Control.) |
|
HandleDestroyed | (Inherited from Control.) |
|
HelpRequested | (Inherited from Control.) |
|
ImeModeChanged | (Inherited from Control.) |
|
Invalidated | (Inherited from Control.) |
|
KeyDown | (Inherited from Control.) |
|
KeyPress | (Inherited from Control.) |
|
KeyUp | (Inherited from Control.) |
|
Layout | (Inherited from Control.) |
|
Leave | (Inherited from Control.) |
|
Load | (Inherited from UserControl.) |
|
LocationChanged | (Inherited from Control.) |
|
LostFocus | (Inherited from Control.) |
|
MarginChanged | (Inherited from Control.) |
|
MouseCaptureChanged | (Inherited from Control.) |
|
MouseClick | (Inherited from Control.) |
|
MouseDoubleClick | (Inherited from Control.) |
|
MouseDown | (Inherited from Control.) |
|
MouseEnter | (Inherited from Control.) |
|
MouseHover | (Inherited from Control.) |
|
MouseLeave | (Inherited from Control.) |
|
MouseMove | (Inherited from Control.) |
|
MouseUp | (Inherited from Control.) |
|
MouseWheel | (Inherited from Control.) |
|
Move | (Inherited from Control.) |
|
PaddingChanged | (Inherited from Control.) |
|
Paint | (Inherited from Control.) |
|
ParentChanged | (Inherited from Control.) |
|
PreviewKeyDown | (Inherited from Control.) |
|
QueryAccessibilityHelp | (Inherited from Control.) |
|
QueryContinueDrag | (Inherited from Control.) |
|
RegionChanged | (Inherited from Control.) |
|
Resize | (Inherited from Control.) |
|
RightToLeftChanged | (Inherited from Control.) |
|
Scroll | (Inherited from ScrollableControl.) |
|
SizeChanged | (Inherited from Control.) |
|
StyleChanged | (Inherited from Control.) |
|
SystemColorsChanged | (Inherited from Control.) |
|
TabIndexChanged | (Inherited from Control.) |
|
TabStopChanged | (Inherited from Control.) |
|
TextChanged | (Inherited from Control.) |
|
Validated | (Inherited from Control.) |
|
Validating | (Inherited from Control.) |
|
VisibleChanged | (Inherited from Control.) |
Explicit Interface Implementations
Name | Description | |
---|---|---|
IContainerControl.ActivateControl(Control) | (Inherited from ContainerControl.) |
|
IDropTarget.OnDragDrop(DragEventArgs) | (Inherited from Control.) |
|
IDropTarget.OnDragEnter(DragEventArgs) | (Inherited from Control.) |
|
IDropTarget.OnDragLeave(EventArgs) | (Inherited from Control.) |
|
IDropTarget.OnDragOver(DragEventArgs) | (Inherited from Control.) |
Remarks
A LineShape, OvalShape, or RectangleShape control can be contained only in a ShapeContainer object, which acts as a canvas for line and shape controls.
When you add a line or shape to a form or container at design time, a ShapeContainer is automatically created if one does not already exist. The Parent property of the line or shape is set to that ShapeContainer. The Parent property of the ShapeContainer is set to the form or container control to which the line or shape was added.
When you create a line or shape at run time by using the New method, the control's Parent property must be set to a ShapeContainer. If a ShapeContainer already exists for the form or container, you should set the Parent property to that ShapeContainer. If no ShapeContainer exists, you can create a ShapeContainer by using the New method and set its Parent property to the form or container.
Note
Be careful that you do not create more than one ShapeContainer for each form or container; doing this may introduce unexpected behavior. If you add a design-time line or shape control to a form or container after you write code to create one programmatically, you should modify that code to use the ShapeContainer created by the designer.
Examples
The following example checks for an existing ShapeContainer and sets the Parent property of an OvalShape control created at run time by using the New method.
private void form1_Load(System.Object sender, System.EventArgs e)
{
OvalShape NewOval = new OvalShape();
int i;
bool found = false;
// Loop through the Controls collection.
for (i = 0; i < this.Controls.Count; i++)
{
// If a ShapeContainer is found, make it the parent.
if (this.Controls[i] is ShapeContainer)
{
NewOval.Parent = ((ShapeContainer)this.Controls[i]);
found = true;
break;
}
}
// If no ShapeContainer is found, create one and set the parents.
if (found == false)
{
ShapeContainer sc = new ShapeContainer();
sc.Parent = this;
NewOval.Parent = sc;
}
NewOval.Size = new Size(200, 300);
}
Private Sub Form1_Load() Handles MyBase.Load
Dim NewOval As New OvalShape
Dim i As Integer
Dim found As Boolean
' Loop through the Controls collection.
For i = 0 To Me.Controls.Count - 1
' If a ShapeContainer is found, make it the parent.
If TypeOf Controls.Item(i) Is ShapeContainer Then
NewOval.Parent = Controls.Item(i)
found = True
Exit For
End If
Next
' If no ShapeContainer is found, create one and set the parents.
If found = False Then
Dim sc As New ShapeContainer
sc.Parent = Me
NewOval.Parent = sc
End If
NewOval.Size = New Size(200, 300)
End Sub
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
See Also
Microsoft.VisualBasic.PowerPacks Namespace
Introduction to the Line and Shape Controls (Visual Studio)
How to: Draw Lines with the LineShape Control (Visual Studio)
How to: Draw Shapes with the OvalShape and RectangleShape Controls (Visual Studio)
Return to top