Control.Region プロパティとは? わかりやすく解説

Control.Region プロパティ

コントロール関連付けられたウィンドウ領域取得または設定します

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

解説解説
使用例使用例

ボタン作成しRegionプロパティ使用する方法次のコード例示します。この例を実行するには、roundButton という名前のボタン配置されているフォームに、次のコード貼り付けます。この例では、Paint イベントが、この例で定義されているイベント ハンドラ関連付けられている必要があります

' 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 のセキュリティ.NET Frameworkセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からControl.Region プロパティを検索した結果を表示しています。
Weblioに収録されているすべての辞書からControl.Region プロパティを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からControl.Region プロパティ を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「Control.Region プロパティ」の関連用語

Control.Region プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



Control.Region プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS