Udostępnij za pośrednictwem


Jak: Nadpisać metodę 'OnRender' klasy 'Panel'

W tym przykładzie pokazano, jak zastąpić metodę OnRenderPanel w celu dodania niestandardowych efektów graficznych do elementu układu.

Przykład

Użyj metody OnRender, aby dodać efekty graficzne do elementu renderowanego panelu. Można na przykład użyć tej metody, aby dodać niestandardowe obramowanie lub efekty tła. Obiekt DrawingContext jest przekazywany jako argument, który udostępnia metody rysowania kształtów, tekstu, obrazów lub wideo. W związku z tym ta metoda jest przydatna do dostosowywania obiektu panelu.

// Override the OnRender call to add a Background and Border to the OffSetPanel
protected override void OnRender(DrawingContext dc)
{
    SolidColorBrush mySolidColorBrush  = new SolidColorBrush();
    mySolidColorBrush.Color = Colors.LimeGreen;
    Pen myPen = new Pen(Brushes.Blue, 10);
    Rect myRect = new Rect(0, 0, 500, 500);
    dc.DrawRectangle(mySolidColorBrush, myPen, myRect);
}
' Override the OnRender call to add a Background and Border to the OffSetPanel
Protected Overrides Sub OnRender(ByVal dc As DrawingContext)
    Dim mySolidColorBrush As New SolidColorBrush()
    mySolidColorBrush.Color = Colors.LimeGreen
    Dim myPen As New Pen(Brushes.Blue, 10)
    Dim myRect As New Rect(0, 0, 500, 500)
    dc.DrawRectangle(mySolidColorBrush, myPen, myRect)
End Sub

Zobacz także