首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Telerik,处理单击RadDropDownButton文本区域

Telerik,处理单击RadDropDownButton文本区域
EN

Stack Overflow用户
提问于 2014-08-29 17:23:42
回答 2查看 1.7K关注 0票数 3

我有一个带有预定义文本和一个RadDropDownButtonRadMenuItem

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

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

处理RadMenuItem.Click已经完成,没有问题,但是当我单击控件上的任何地方而不仅仅是文本区域时,RadDropDownButton.Click事件就会触发。

我怎样才能解决这个问题,让控件按我的意愿工作呢?

代码语言:javascript
复制
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
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-08-31 15:58:54

他们的SplitButton有点聪明,国际海事组织。大多数SplitButton将箭头区域视为虚拟按钮,或者跳过发出按钮CLick事件,或者显示相关的下拉菜单(或者两者兼而有之)。当单击该区域时,大多数用户使用一个新的SplitClicked事件,这样您就可以根据需要修改菜单:

代码语言:javascript
复制
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事件总是首先触发):

代码语言:javascript
复制
' 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
票数 2
EN

Stack Overflow用户

发布于 2014-09-02 23:38:39

解决办法:

我称之为“区分箭头单击而没有默认项集”,这对RadDropDownButtonRadSplitButton都适用。

代码语言:javascript
复制
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,但它并没有给出预期的结果。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25573224

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档