Region.GetBounds(Graphics) Metoda
Definicja
Ważne
Niektóre informacje odnoszą się do produktu w wersji wstępnej, który może zostać znacząco zmodyfikowany przed wydaniem. Firma Microsoft nie udziela żadnych gwarancji, jawnych lub domniemanych, w odniesieniu do informacji podanych w tym miejscu.
RectangleF Pobiera strukturę reprezentującą prostokąt, który wiąże tę Region strukturę na powierzchni rysunku Graphics obiektu.
public:
System::Drawing::RectangleF GetBounds(System::Drawing::Graphics ^ g);
public System.Drawing.RectangleF GetBounds (System.Drawing.Graphics g);
member this.GetBounds : System.Drawing.Graphics -> System.Drawing.RectangleF
Public Function GetBounds (g As Graphics) As RectangleF
Parametry
Zwraca
RectangleF Struktura reprezentująca prostokąt ograniczenia dla tego Region elementu na określonej powierzchni rysunku.
Wyjątki
g
to null
.
Przykłady
Poniższy przykład kodu jest przeznaczony do użycia z Windows Forms i wymaga PaintEventArgse
parametru Paint programu obsługi zdarzeń. Kod wykonuje następujące akcje:
Tworzy element GraphicsPath i dodaje do niego wielokropek.
Wypełnia ścieżkę niebieską i rysuje ją na ekranie.
Tworzy region, w którym jest używany GraphicsPathelement .
Pobiera brakxcluded obszaru regionu w połączeniu z drugim prostokątem.
Pobiera prostokąt ograniczenia dla regionu i rysuje go na ekranie w kolorze czerwonym.
public:
void GetBoundsExample( PaintEventArgs^ e )
{
// Create a GraphicsPath and add an ellipse to it.
GraphicsPath^ myPath = gcnew GraphicsPath;
Rectangle ellipseRect = Rectangle(20,20,100,100);
myPath->AddEllipse( ellipseRect );
// Fill the path with blue and draw it to the screen.
SolidBrush^ myBrush = gcnew SolidBrush( Color::Blue );
e->Graphics->FillPath( myBrush, myPath );
// Create a region using the GraphicsPath.
System::Drawing::Region^ myRegion = gcnew System::Drawing::Region( myPath );
// Get the bounding rectangle for myRegion and draw it to the
// screen in Red.
RectangleF boundsRect = myRegion->GetBounds( e->Graphics );
e->Graphics->DrawRectangle( Pens::Red, Rectangle::Round( boundsRect ) );
}
public void GetBoundsExample(PaintEventArgs e)
{
// Create a GraphicsPath and add an ellipse to it.
GraphicsPath myPath = new GraphicsPath();
Rectangle ellipseRect = new Rectangle(20, 20, 100, 100);
myPath.AddEllipse(ellipseRect);
// Fill the path with blue and draw it to the screen.
SolidBrush myBrush = new SolidBrush(Color.Blue);
e.Graphics.FillPath(myBrush, myPath);
// Create a region using the GraphicsPath.
Region myRegion = new Region(myPath);
// Get the bounding rectangle for myRegion and draw it to the
// screen in Red.
RectangleF boundsRect = myRegion.GetBounds(e.Graphics);
e.Graphics.DrawRectangle(Pens.Red, Rectangle.Round(boundsRect));
}
Public Sub GetBoundsExample(ByVal e As PaintEventArgs)
' Create a GraphicsPath and add an ellipse to it.
Dim myPath As New GraphicsPath
Dim ellipseRect As New Rectangle(20, 20, 100, 100)
myPath.AddEllipse(ellipseRect)
' Fill the path with blue and draw it to the screen.
Dim myBrush As New SolidBrush(Color.Blue)
e.Graphics.FillPath(myBrush, myPath)
' Create a region using the GraphicsPath.
Dim myRegion As New [Region](myPath)
' Get the bounding rectangle for myRegion and draw it to the
' screen in Red.
Dim boundsRect As RectangleF = myRegion.GetBounds(e.Graphics)
e.Graphics.DrawRectangle(Pens.Red, Rectangle.Round(boundsRect))
End Sub
Uwagi
Bieżąca transformacja kontekstu graficznego służy do obliczania wnętrza regionu na powierzchni rysunku. Prostokąt ograniczenia nie zawsze jest najmniejszym możliwym prostokątem ograniczenia w zależności od bieżącej transformacji.
Dotyczy
Opinia
https://aka.ms/ContentUserFeedback.
Dostępne już wkrótce: W 2024 r. będziemy stopniowo wycofywać zgłoszenia z serwisu GitHub jako mechanizm przesyłania opinii na temat zawartości i zastępować go nowym systemem opinii. Aby uzyskać więcej informacji, sprawdź:Prześlij i wyświetl opinię dla