共用方式為


SimpleShape.OnPaint 方法

引發 Paint 事件。

命名空間:  Microsoft.VisualBasic.PowerPacks
組件:  Microsoft.VisualBasic.PowerPacks.Vs (在 Microsoft.VisualBasic.PowerPacks.Vs.dll 中)

語法

'宣告
Protected Friend Overrides Sub OnPaint ( _
    e As PaintEventArgs _
)
protected internal override void OnPaint(
    PaintEventArgs e
)
protected public:
virtual void OnPaint(
    PaintEventArgs^ e
) override
abstract OnPaint : 
        e:PaintEventArgs -> unit 
override OnPaint : 
        e:PaintEventArgs -> unit 
 override function OnPaint(
    e : PaintEventArgs
)

參數

備註

引發事件會透過委派 (Delegate) 叫用事件處理常式。如需詳細資訊,請參閱引發事件

OnPaint 方法也允許衍生類別處理事件,而不用附加委派。這是在衍生類別中處理事件的慣用技術。

繼承者注意事項

覆寫衍生類別中的 OnPaint 時,請務必呼叫基底類別的 OnPaint 方法,如此登錄的委派才能接收事件。

範例

下列範例是一種方法的執行時機Click事件,就會發生。Shape類別有幾個方法具有名稱模式OnEventName 的執行的方法時 EventName 事件,就會發生。(EventName 代表相對應的事件名稱。)

下列範例會示範如何覆寫OnClickOnLostFocus方法從衍生類別中的LineShape

Public Class HighlightLine
    Inherits LineShape
    Protected Overrides Sub OnClick(ByVal e As EventArgs)
        ' Change the color of the line when clicked.
        Me.BorderColor = Color.Red
        MyBase.OnClick(e)
    End Sub
    Protected Overrides Sub OnLostFocus(ByVal e As System.EventArgs)
        ' Change the color of the line when focus is changed.
        Me.BorderColor = Color.Black
        MyBase.OnLostFocus(e)
    End Sub
End Class
public class HighlightLine :
    LineShape
{
    protected override void OnClick(EventArgs e)
    {
        // Change the color of the line when clicked.
        this.BorderColor = Color.Red;
        base.OnClick(e);
    }
    protected override void OnLostFocus(System.EventArgs e)
    {
        // Change the color of the line when focus is changed.
        this.BorderColor = Color.Black;
        base.OnLostFocus(e);
    }
}

.NET Framework 安全性

請參閱

參考

SimpleShape 類別

Microsoft.VisualBasic.PowerPacks 命名空間

其他資源

Line 和 Shape 控制項簡介 (Visual Studio)

HOW TO:使用 LineShape 控制項繪製線條 (Visual Studio)

HOW TO:使用 OvalShape 和 RectangleShape 控制項繪製圖案 (Visual Studio)