Shape.Region-Eigenschaft

Ruft den Fensterbereich ab oder legt diesen fest, der mit einem Linien-oder Formsteuerelement zugeordnet ist.

Namespace:  Microsoft.VisualBasic.PowerPacks
Assembly:  Microsoft.VisualBasic.PowerPacks.Vs (in Microsoft.VisualBasic.PowerPacks.Vs.dll)

Syntax

'Declaration
<BrowsableAttribute(False)> _
Public Property Region As Region
[BrowsableAttribute(false)]
public Region Region { get; set; }
[BrowsableAttribute(false)]
public:
property Region^ Region {
    Region^ get ();
    void set (Region^ value);
}
[<BrowsableAttribute(false)>]
member Region : Region with get, set
function get Region () : Region
function set Region (value : Region)

Eigenschaftswert

Typ: System.Drawing.Region
Die dem Steuerelement zugeordnete Fenster-Region.

Hinweise

Der Fensterbereich ist eine Auflistung von Pixel im Fenster, in dem das Betriebssystem Zeichnung aktiviert.Das Betriebssystem wird kein Teil eines Fensters, das Fenster außerhalb des Bereichs liegt.Die Koordinaten des Bereichs eines Steuerelements werden relativ zur linken oberen Ecke des Steuerelements angegeben, nicht relativ zum Clientbereich des Steuerelements.

Beispiele

Im folgenden Beispiel wird veranschaulicht, wie die Region-Eigenschaft verwendet, um RectangleShape in ein halb-transparentes Oval zu ändern.Dieses Beispiel setzt voraus, dass Sie RectangleShape verfügen, das in einem Formular RectangleShape1.Um den halb-transparenten Effekt anzuzeigen, weisen Sie ein Bild zur BackgroundImage-Eigenschaft des Formulars auf.

Private Sub RectangleShape1_Paint(
    ByVal sender As Object, 
    ByVal e As System.Windows.Forms.PaintEventArgs
  ) Handles RectangleShape1.Paint

    Dim shapePath As New System.Drawing.Drawing2D.GraphicsPath

    ' Set a new rectangle to the same size as the RectangleShape's 
    ' ClientRectangle property.
    Dim newRectangle As Rectangle = RectangleShape1.ClientRectangle

    ' Decrease the size of the rectangle.
    newRectangle.Inflate(-10, -10)

    ' Draw the new rectangle's border.
    e.Graphics.DrawEllipse(System.Drawing.Pens.Black, newRectangle)

    ' Create a semi-transparent brush.
    Dim br As New SolidBrush(Color.FromArgb(128, 0, 0, 255))

    ' Fill the new rectangle.
    e.Graphics.FillEllipse(br, newRectangle)
    'Increase the size of the rectangle to include the border.
    newRectangle.Inflate(1, 1)

    ' Create an oval region within the new rectangle.
    shapePath.AddEllipse(newRectangle)
    e.Graphics.DrawPath(Pens.Black, shapePath)

    ' Set the RectangleShape's Region property to the newly created 
    ' oval region.
    RectangleShape1.Region = New System.Drawing.Region(shapePath)
End Sub
private void rectangleShape1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{

    System.Drawing.Drawing2D.GraphicsPath shapePath = new System.Drawing.Drawing2D.GraphicsPath();

    // Set a new rectangle to the same size as the RectangleShape's 
    // ClientRectangle property.
    Rectangle newRectangle = rectangleShape1.ClientRectangle;

    // Decrease the size of the rectangle.
    newRectangle.Inflate(-10, -10);

    // Draw the new rectangle's border.
    e.Graphics.DrawEllipse(System.Drawing.Pens.Black, newRectangle);

    // Create a semi-transparent brush.
    SolidBrush br = new SolidBrush(Color.FromArgb(128, 0, 0, 255));

    // Fill the new rectangle.
    e.Graphics.FillEllipse(br, newRectangle);
    //Increase the size of the rectangle to include the border.
    newRectangle.Inflate(1, 1);

    // Create an oval region within the new rectangle.
    shapePath.AddEllipse(newRectangle);
    e.Graphics.DrawPath(Pens.Black, shapePath);

    // Set the RectangleShape's Region property to the newly created 
    // oval region.
    rectangleShape1.Region = new System.Drawing.Region(shapePath);
}

.NET Framework-Sicherheit

Siehe auch

Referenz

Shape Klasse

Microsoft.VisualBasic.PowerPacks-Namespace

Weitere Ressourcen

Gewusst wie: Zeichnen von Linien mit dem LineShape-Steuerelement (Visual Studio)

Gewusst wie: Zeichnen von Formen mit dem OvalShape-Steuerelement und dem RectangleShape-Steuerelement (Visual Studio)

Einführung in das Line-Steuerelement und das Shape-Steuerelement (Visual Studio)