Stylus.StylusButtonDown Stylus.StylusButtonDown Stylus.StylusButtonDown Attached Event

定義

使用者按下手寫筆上其中一個按鈕時發生。Occurs when the user presses one of the buttons on the stylus.

see AddStylusButtonDownHandler, and RemoveStylusButtonDownHandler
see AddStylusButtonDownHandler, and RemoveStylusButtonDownHandler
see AddStylusButtonDownHandler, and RemoveStylusButtonDownHandler

範例

下列範例示範當使用者按下手寫筆上的 [圓筒] 按鈕時, 如何顯示快捷方式功能表。The following example demonstrates how to show a shortcut menu when the user presses the barrel button on a stylus. 這個範例假設有一個TextBox呼叫textBox1的和ContextMenutextBoxContextMenu為的, 而且該StylusButtonDown事件已連接到事件處理常式。This example assumes that there is a TextBox called textBox1, and a ContextMenu called textBoxContextMenu, and that the StylusButtonDown event is connected to the event handler.

// Show or hide a shortcut menu when the user clicks the barrel button.
void textbox1_StylusButtonDown(object sender, StylusButtonEventArgs e)
{
    if (e.StylusButton.Guid != StylusPointProperties.BarrelButton.Id)
    {
        return;
    }

    if (textbox1.ContextMenu == null)
    {
        textbox1.ContextMenu = textBoxContextMenu;
    }
    else
    {
        textbox1.ContextMenu = null;
    }
}
' Show or hide a shortcut menu when the user clicks the barrel button.
Private Sub textbox1_StylusButtonDown(ByVal sender As Object, ByVal e As StylusButtonEventArgs) _
    Handles textbox1.StylusButtonDown

    If e.StylusButton.Guid <> StylusPointProperties.BarrelButton.Id Then
        Return
    End If

    If textbox1.ContextMenu Is Nothing Then
        textbox1.ContextMenu = textBoxContextMenu
    Else
        textbox1.ContextMenu = Nothing
    End If

End Sub

備註

這是附加事件。This is an attached event. WPFWPF將附加事件實作為路由事件。implements attached events as routed events. 附加事件基本上是一種XAMLXAML語言概念, 用來參考在不會定義事件的物件上處理的事件。An attached event is, fundamentally, a XAMLXAML language concept used to reference events that are handled on objects that do not, themselves, define events. WPFWPF進一步擴充附加事件的功能, 讓它能夠跨越路由。further expands an attached event's capabilities, allowing it to traverse a route. 附加事件在程式碼中沒有直接處理語法;若要在程式碼中附加路由事件的處理常式, 請使用指定的 Add * 處理常式方法。Attached events do not have a direct handling syntax in code; to attach handlers for a routed event in code, use a designated Add*Handler method. 如需詳細資訊, 請參閱附加事件總覽For details, see Attached Events Overview.

路由事件資訊Routed Event Information

識別碼欄位Identifier field StylusButtonDownEvent
路由策略Routing strategy 路由Bubbling
Delegate - 委派Delegate StylusButtonEventHandler

適用於

另請參閱