自訂控制項
Public Class SuperButton Inherits Button Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs) MyBase.OnPaint(e) '請在此處加入您自訂的繪製程式碼 End Sub '自訂一個新的事件RightClick Dim _handlers As New List(Of EventHandler) Public Custom Event RightClick As EventHandler AddHandler(value As EventHandler) _handlers.Add(value) End AddHandler RemoveHandler(value As EventHandler) If _handlers.Contains(value) Then _handlers.Remove(value) End If End RemoveHandler RaiseEvent(sender As Object, e As System.EventArgs) For Each handler As EventHandler In _handlers Try handler.Invoke(sender, e) Catch ex As Exception Debug.WriteLine(ex.ToString()) End Try Next End RaiseEvent End Event '監聽滑鼠事件 Protected Overrides Sub OnMouseDown(mevent As System.Windows.Forms.MouseEventArgs) MyBase.OnMouseDown(mevent) '當滑鼠被按下右鍵時則回應自訂事件 If mevent.Button = Windows.Forms.MouseButtons.Right Then RaiseEvent RightClick(Me, mevent) End If End Sub End Class
沒有留言:
張貼留言