2014-08-29 23 views
2

我有一个RadDropDownButton与预定义的文本,然后用一个RadMenuItemTelerik的,手柄上RadDropDownButton文本区点击

enter image description here

我的本意是,当我点击文本区上执行动作(NOT箭头):

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 
+0

你可以显示Click和ItemChanged事件的代码吗?为什么你不能注释掉RadDropDownButton点击或添加一些代码来检查特定的条件..? – MethodMan 2014-08-29 17:35:02

+0

@DJ KRAZE对不起,但我认为这个问题不需要提供代码,因为它是不言自明的,反正我已经添加了一个代码(我不必处理ItemChanged事件,我只有1个项目),我想问的是:想象一下当你点击控件时想要启动一个MsgBox的情况,但是你也希望能够在没有启动msgbox ofcourse的情况下点击箭头时打开菜单if你打开菜单,你会选择一个项目,将执行其他事情(例如启动一个不同的msgbox)。你知道我吗?对不起我的英语不好! – ElektroStudios 2014-08-29 18:06:26

+0

您可以检查鼠标位置与控件的边界吗? – djv 2014-08-29 22:23:18

回答

1

他们的SplitButton有点braindead,国际海事组织。大多数SplitButton s将箭头区域视为虚拟按钮,或者跳过发出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 
+0

比这更容易,只是我需要设置RadSplitButton的'DefaultItem'属性,然后当你点击“文本区域”时,它会默认点击这个默认项目,你可以点击箭头选择另一个项目,反正你的答案是一个非常好的选择,我会测试好奇心! – ElektroStudios 2014-08-31 16:04:11

+0

但这只有在有默认项目时才有效,不是? – Plutonix 2014-08-31 16:05:55

+0

我想是的:(所以你的方式似乎更完美'因为我可以避免在控件上生成该默认项目,再次感谢 – ElektroStudios 2014-08-31 16:06:36

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但它不会产生预期的结果。