IMO,他们的 SplitButton 有点脑残。大多数SplitButton
s 将箭头区域视为一个虚拟按钮,并且要么跳过发出 Button CLick 事件,要么改为显示相关的下拉菜单(或两者兼而有之)。大多数人在单击该区域时使用新的 SplitClicked 事件,以便您可以根据需要调整菜单:
Protected Overrides Sub OnMouseDown(ByVal mevent As MouseEventArgs)
...
' they clicked in the arrow.split rect
If (SplitRect.Contains(mevent.Location)) Then
' notify them
RaiseEvent SplitClick(Me, New EventArgs)
' open the menu if there is one
If ShowContextMenuStrip() = False Then
skipNextClick = True ' fixup for the menu
End If
Else
' let the normal event get raised
State = PushButtonState.Pressed
MyBase.OnMouseDown(mevent)
End If
End Sub
它们没有类似的事件,但作为一种解决方法,您可以使用该DropDownOpening
事件来“取消”按钮单击事件,如下所示(这是因为 DropDownOpening 事件总是首先触发):
' workaround flag
Private IgnoreClickBecauseMenuIsOpening As Boolean
Private Sub RadSplitButton1_DropDownOpening(sender As Object,
e As EventArgs) Handles RadSplitButton1.DropDownOpening
IgnoreClickBecauseMenuIsOpening = True
' code to modify menu (or not)
End Sub
Private Sub RadSplitButton1_Click(sender As Object,
e As EventArgs) Handles RadSplitButton1.Click
' ignore click if menu is opening
If IgnoreClickBecauseMenuIsOpening Then
' reset flag
IgnoreClickBecauseMenuIsOpening = False
Exit Sub ' all done here
End If
' normal code to execute for a click
End Sub