我有一个带有预定义文本和一个 RadMenuItem
的 RadDropDownButton
:
我的意图是在单击文本区域(而不是箭头)时执行操作:
然后当我点击可选项目时执行其他操作:
处理 RadMenuItem.Click
已完成,没问题,但是 RadDropDownButton.Click
事件会在我点击控件的任何地方而不仅仅是在文本中时触发区域。
如何解决这个问题,让控件按我希望的方式工作?
Private sub MyRadDropDownButton_click() handles MyRadDropDownButton.click
' this instruction should be launched only when clicking on the "Analyze" word.
' this means everywhere on the control but not on the arrow.
msgbox("you've clicked on the "Analyze" word")
end sub
最佳答案
他们的 SplitButton 有点脑残,IMO。大多数 SplitButton
将箭头区域视为虚拟按钮,并跳过发出 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
关于c# - Telerik,处理点击 RadDropDownButton 文本区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25573224/