Propriedade Shape.Region
Obtém ou define a região da janela associada a um controle de linha ou de forma.
Namespace: Microsoft.VisualBasic.PowerPacks
Assembly: Microsoft.VisualBasic.PowerPacks.Vs (em Microsoft.VisualBasic.PowerPacks.Vs.dll)
Sintaxe
'Declaração
<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)
Valor de propriedade
Tipo: Region
A janela Region associado ao controle.
Comentários
O região da janela é uma coleção de pixels na janela onde o sistema operacional permite que o desenho. O sistema operacional não exibe qualquer parte de uma janela que está fora da região de janela. As coordenadas da região do controle são relativas ao canto superior esquerdo do controle, não a área do cliente do controle.
Exemplos
O exemplo a seguir demonstra como usar o Region propriedade para alterar uma RectangleShape em uma elipse semitransparente. Este exemplo requer que você tenha um RectangleShape chamado RectangleShape1 em um formulário. Para ver o efeito semitransparente, atribuir uma imagem para o BackgroundImage propriedades do formulário.
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);
}
Segurança do .NET Framework
- Confiança total para o chamador imediato. O membro não pode ser usado por código parcialmente confiável. Para obter mais informações, consulte Usando bibliotecas de código parcialmente confiável.
Consulte também
Referência
Namespace Microsoft.VisualBasic.PowerPacks
Outros recursos
Como desenhar linhas com o controle LineShape (Visual Studio)
Como desenhar formas com os controles OvalShape e RectangleShape (Visual Studio)