c# - Telerik,处理点击 RadDropDownButton 文本区域

标签 c# vb.net winforms telerik raddropdownbutton

我有一个带有预定义文本和一个 RadMenuItemRadDropDownButton:

enter image description here

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

enter image description here

然后当我点击可选项目时执行其他操作:

enter image description here

处理 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/

相关文章:

c# - 使用 BackGroundWorker 运行 WatiN 打开 IE 浏览器

C# 随机消失的用户控件

c# - ExpertPdf 转换错误 : WebKit Navigation timeout in GetPdfBytesFromUrl

vb.net - 列表字符串字符串索引?

javascript - 在 asp.net 中自动调整面板中子控件的大小

vb.net - Linq 左外连接

.net - 如何显示.NET Balloon工具提示?

c# - Gmail API 读取邮件

c# - 为什么任务取消发生在调用者线程上?

c# - 不使用正则表达式检查特殊字符