我有一个带有预定义文本和一个RadDropDownButton的RadMenuItem

当我单击文本区域(而不是箭头)时,我的意图是执行一个操作:

然后在单击可选择项时执行其他操作:

处理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发布于 2014-08-31 15:58:54
他们的SplitButton有点聪明,国际海事组织。大多数SplitButton将箭头区域视为虚拟按钮,或者跳过发出按钮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发布于 2014-09-02 23:38:39
解决办法:
我称之为“区分箭头单击而没有默认项集”,这对RadDropDownButton和RadSplitButton都适用。
Public Class RadSplitButton_TestForm
''' <summary>
''' Flag that determines whether the RadSplitButton menu-opening should be canceled.
''' </summary>
Private CancelOpening As Boolean = False
Private Sub RadSplitButton1_DropDownOpening(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) _
Handles RadSplitButton1.DropDownOpening
e.Cancel = Me.CancelOpening
End Sub
Private Sub RadSplitButton1_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) _
Handles RadSplitButton1.MouseMove
Me.CancelOpening = Not sender.DropDownButtonElement.ArrowButton.IsMouseOverElement
End Sub
Private Sub RadSplitButton1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) _
Handles RadSplitButton1.Click
If e.Button = Windows.Forms.MouseButtons.Left AndAlso Me.CancelOpening Then
MsgBox("clicked out the arrow!")
ElseIf Not Me.CancelOpening Then
MsgBox("clicked over the arrow!")
End If
End Sub
End ClassPS:首先,我试图确定mouseposition是否超过了ArrowButton.ClientRectangle,但它并没有给出预期的结果。
https://stackoverflow.com/questions/25573224
复制相似问题