3

我有一个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
4

2 回答 2

2

IMO,他们的 SplitButton 有点脑残。大多数SplitButtons 将箭头区域视为一个虚拟按钮,并且要么跳过发出 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
于 2014-08-31T15:58:54.420 回答
0

解决方案:

我将此称为“区分没有默认项目集的箭头单击”,这适用于RadDropDownButtonRadSplitButton

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 Class

PS:首先我试图确定是否mouseposition结束,ArrowButton.ClientRectangle但它没有给出预期的结果。

于 2014-09-02T23:38:39.773 回答