3

私はRadDropDownButton事前定義されたテキストと1つを持っています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

彼らの 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
于 2014-08-31T15:58:54.420 に答える
0

ソリューション:

私はこれを「デフォルト項目を設定せずに矢印クリックを区別する」と呼びました。これは と の両方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 Class

PS: まず、mousepositionが を超えているかどうかを判断しようとしましたArrowButton.ClientRectangleが、期待どおりの結果が得られませんでした。

于 2014-09-02T23:38:39.773 に答える