Shape.Region 屬性
取得或設定與線條或圖形控制項關聯的視窗區域。
命名空間: Microsoft.VisualBasic.PowerPacks
組件: Microsoft.VisualBasic.PowerPacks.Vs (在 Microsoft.VisualBasic.PowerPacks.Vs.dll 中)
語法
'宣告
<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)
屬性值
類型:Region
與控制項關聯的視窗 Region。
備註
視窗區域是集合,其中作業系統會啟用繪圖視窗中的像素。 作業系統不會顯示視窗的視窗區域以外的任何的部分。 控制項的座標是區域的相對於控制項,而不控制項的用戶端區域的左上角。
範例
下列範例示範如何使用Region屬性來變更RectangleShape到半透明橢圓形。 此範例中您需要RectangleShape名 RectangleShape1 為表單上。 若要查看半透明效果,指派影像來BackgroundImage表單的屬性。
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 安全性
- 完全信任立即呼叫者。這個成員無法供部分信任的程式碼使用。如需詳細資訊,請參閱從部分受信任程式碼使用程式庫。
請參閱
參考
Microsoft.VisualBasic.PowerPacks 命名空間
其他資源
如何:使用 LineShape 控制項繪製線條 (Visual Studio)