Freigeben über


Control.Region-Eigenschaft

Ruft den dem Steuerelement zugeordneten Fensterbereich ab oder legt diesen fest.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

Syntax

'Declaration
Public Property Region As Region
'Usage
Dim instance As Control
Dim value As Region

value = instance.Region

instance.Region = value
public Region Region { get; set; }
public:
property Region^ Region {
    Region^ get ();
    void set (Region^ value);
}
/** @property */
public Region get_Region ()

/** @property */
public void set_Region (Region value)
public function get Region () : Region

public function set Region (value : Region)

Eigenschaftenwert

Die dem Steuerelement zugeordnete Fenster-Region.

Hinweise

Der Fensterbereich ist eine Auflistung von Pixeln innerhalb des Fensters, in dem das Betriebssystem Zeichnen zulässt. Das Betriebssystem zeigt außerhalb des Fensterbereichs liegende Teile des Fensters nicht an. Die Koordinaten des Bereichs eines Steuerelements werden relativ zur linken oberen Ecke des Steuerelements angegeben, nicht relativ zum Clientbereich des Steuerelements.

Hinweis

Die Auflistung der Pixel innerhalb des Bereichs kann lückenhaft sein.

Beispiel

Im folgenden Codebeispiel wird die Verwendung der Region-Eigenschaft durch das Erstellen einer runden Schaltfläche veranschaulicht. Fügen Sie zum Ausführen des Beispiels den folgenden Code in ein Formular ein, das eine Schaltfläche mit dem Namen roundButton enthält. Für dieses Beispiel muss das Paint-Ereignis des im Beispiel definierten Ereignishandlers zugeordnet sein.

' This method will change the square button to a circular button by 
' creating a new circle-shaped GraphicsPath object and setting it 
' to the RoundButton objects region.
Private Sub roundButton_Paint(ByVal sender As Object, _
    ByVal e As System.Windows.Forms.PaintEventArgs) Handles roundButton.Paint

    Dim buttonPath As New System.Drawing.Drawing2D.GraphicsPath

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

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

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

    'Increase the size of the rectangle to include the border.
    newRectangle.Inflate(1, 1)

    ' Create a circle within the new rectangle.
    buttonPath.AddEllipse(newRectangle)
    e.Graphics.DrawPath(Pens.Black, buttonPath)
    ' Set the button's Region property to the newly created 
    ' circle region.
    roundButton.Region = New System.Drawing.Region(buttonPath)

End Sub
// This method will change the square button to a circular button by 
// creating a new circle-shaped GraphicsPath object and setting it 
// to the RoundButton objects region.
private void roundButton_Paint(object sender, 
    System.Windows.Forms.PaintEventArgs e)
{

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

    // Set a new rectangle to the same size as the button's 
    // ClientRectangle property.
    System.Drawing.Rectangle newRectangle = roundButton.ClientRectangle;

    // Decrease the size of the rectangle.
    newRectangle.Inflate(-10, -10);
    
    // Draw the button's border.
    e.Graphics.DrawEllipse(System.Drawing.Pens.Black, newRectangle);

    // Increase the size of the rectangle to include the border.
    newRectangle.Inflate( 1,  1);

    // Create a circle within the new rectangle.
    buttonPath.AddEllipse(newRectangle);
            
    // Set the button's Region property to the newly created 
    // circle region.
    roundButton.Region = new System.Drawing.Region(buttonPath);

}
private:
   // This method will change the square button to a circular button by 
   // creating a new circle-shaped GraphicsPath object and setting it 
   // to the RoundButton objects region.
   void roundButton_Paint( Object^ sender,
      System::Windows::Forms::PaintEventArgs^ e )
   {
      System::Drawing::Drawing2D::GraphicsPath^ buttonPath =
         gcnew System::Drawing::Drawing2D::GraphicsPath;
      
      // Set a new rectangle to the same size as the button's 
      // ClientRectangle property.
      System::Drawing::Rectangle newRectangle = roundButton->ClientRectangle;
      
      // Decrease the size of the rectangle.
      newRectangle.Inflate(  -10, -10 );
      
      // Draw the button's border.
      e->Graphics->DrawEllipse( System::Drawing::Pens::Black, newRectangle );
      
      // Increase the size of the rectangle to include the border.
      newRectangle.Inflate( 1, 1 );
      
      // Create a circle within the new rectangle.
      buttonPath->AddEllipse( newRectangle );
      
      // Set the button's Region property to the newly created 
      // circle region.
      roundButton->Region = gcnew System::Drawing::Region( buttonPath );
   }
// This method will change the square button to a circular button by 
// creating a new circle-shaped GraphicsPath object and setting it 
// to the RoundButton objects region.
private void roundButton_Paint(Object sender, 
    System.Windows.Forms.PaintEventArgs e)
{
    System.Drawing.Drawing2D.GraphicsPath buttonPath = 
        new System.Drawing.Drawing2D.GraphicsPath();
    // Set a new rectangle to the same size as the button's 
    // ClientRectangle property.
    System.Drawing.Rectangle newRectangle = 
        roundButton.get_ClientRectangle();
    // Decrease the size of the rectangle.
    newRectangle.Inflate(-10, -10);
    // Draw the button's border.
    e.get_Graphics().DrawEllipse(System.Drawing.Pens.get_Black(), 
        newRectangle);
    // Increase the size of the rectangle to include the border.
    newRectangle.Inflate(1, 1);
    // Create a circle within the new rectangle.
    buttonPath.AddEllipse(newRectangle);
    // Set the button's Region property to the newly created 
    // circle region.
    roundButton.set_Region(new System.Drawing.Region(buttonPath));
} //roundButton_Paint 

.NET Framework-Sicherheit

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

Control-Klasse
Control-Member
System.Windows.Forms-Namespace
Control.ClientRectangle-Eigenschaft
Control.Bounds-Eigenschaft