Private m_objLefthandedButtons As New Dictionary(Of Integer, KeyValuePair(Of Action, Image))
Private m_objRighthandedButtons As New Dictionary(Of Integer, KeyValuePair(Of Action, Image))
Public Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
m_objLefthandedButtons.Add(0, New KeyValuePair(Of Action, Image)(New Action(AddressOf OnDownButtonClicked), My.Resources.down))
m_objLefthandedButtons.Add(1, New KeyValuePair(Of Action, Image)(New Action(AddressOf OnOkButtonClicked), My.Resources.ok2))
m_objLefthandedButtons.Add(2, New KeyValuePair(Of Action, Image)(New Action(AddressOf OnUpButtonClicked), My.Resources.up))
m_objLefthandedButtons.Add(3, New KeyValuePair(Of Action, Image)(New Action(AddressOf OnCancelButtonClicked), My.Resources.back))
m_objRighthandedButtons.Add(0, New KeyValuePair(Of Action, Image)(New Action(AddressOf OnCancelButtonClicked), My.Resources.back))
m_objRighthandedButtons.Add(1, New KeyValuePair(Of Action, Image)(New Action(AddressOf OnUpButtonClicked), My.Resources.up))
m_objRighthandedButtons.Add(2, New KeyValuePair(Of Action, Image)(New Action(AddressOf OnOkButtonClicked), My.Resources.ok2))
m_objRighthandedButtons.Add(3, New KeyValuePair(Of Action, Image)(New Action(AddressOf OnDownButtonClicked), My.Resources.down))
End Sub
Public ReadOnly Property Buttons As Dictionary(Of Integer, KeyValuePair(Of Action, Image))
Get
If Me.LeftHanded Then
Return m_objLefthandedButtons
Else
Return m_objRighthandedButtons
End If
End Get
End Property
Private m_blnLeftHanded As Boolean = False
Public Property LeftHanded() As Boolean
Get
Return m_blnLeftHanded
End Get
Set(ByVal value As Boolean)
m_blnLeftHanded = value
Me.Invalidate()
End Set
End Property
Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
MyBase.OnMouseDown(e)
Dim i As Integer = Me.GetClickedIndex(e.Location) 'gets the index (key) of the button that was clicked from the location
' invoke it
Me.Invoke(Me.Buttons(i).Key)
End Sub
Protected Overridable Sub OnUpButtonClicked()
RaiseEvent UpButtonClicked(Me, EventArgs.Empty)
End Sub
Protected Overridable Sub OnDownButtonClicked()
RaiseEvent DownButtonClicked(Me, EventArgs.Empty)
End Sub
Protected Overridable Sub OnOkButtonClicked()
RaiseEvent OkButtonClicked(Me, EventArgs.Empty)
End Sub
Protected Overridable Sub OnCancelButtonClicked()
RaiseEvent CancelButtonClicked(Me, EventArgs.Empty)
End Sub