MouseButtonEventArgs MouseButtonEventArgs MouseButtonEventArgs MouseButtonEventArgs Class

定義

提供滑鼠按鍵相關事件的資料。Provides data for mouse button related events.

public ref class MouseButtonEventArgs : System::Windows::Input::MouseEventArgs
public class MouseButtonEventArgs : System.Windows.Input.MouseEventArgs
type MouseButtonEventArgs = class
    inherit MouseEventArgs
Public Class MouseButtonEventArgs
Inherits MouseEventArgs
繼承

範例

下列範例會建立一個滑鼠按鍵事件處理常式, 以變更引發事件之物件的色彩。The following example creates a mouse button event handler that changes the color of the object that raised the event. 選擇的色彩取決於按下的滑鼠按鍵。The color chosen depends on the mouse button which was pressed. ChangedButton檢查屬性, 以判斷所按的按鈕。The ChangedButton property is checked to determine which button was pressed.

private void MouseButtonDownHandler(object sender, MouseButtonEventArgs e)
{
    Control src = e.Source as Control;

    if (src != null)
    {
        switch (e.ChangedButton)
        {
            case MouseButton.Left:
                src.Background = Brushes.Green;
                break;
            case MouseButton.Middle:
                src.Background = Brushes.Red;
                break;
            case MouseButton.Right:
                src.Background = Brushes.Yellow;
                break;
            case MouseButton.XButton1:
                src.Background = Brushes.Brown;
                break;
            case MouseButton.XButton2:
                src.Background = Brushes.Purple;
                break;
            default:
                break;
        }
    }
}
Private Sub MouseButtonDownHandler(ByVal sender As Object, ByVal e As MouseButtonEventArgs)
    Dim src As Control = TryCast(e.Source, Control)

    If src IsNot Nothing Then
        Select Case e.ChangedButton
            Case MouseButton.Left
                src.Background = Brushes.Green
            Case MouseButton.Middle
                src.Background = Brushes.Red
            Case MouseButton.Right
                src.Background = Brushes.Yellow
            Case MouseButton.XButton1
                src.Background = Brushes.Brown
            Case MouseButton.XButton2
                src.Background = Brushes.Purple
            Case Else
        End Select
    End If
End Sub

備註

MouseButtonEventArgs會搭配下列事件使用: MouseDownMouseUpMouseLeftButtonDownMouseLeftButtonUpMouseRightButtonDownMouseRightButtonUp和對應的通道事件。MouseButtonEventArgs is used with the following events: MouseDown, MouseUp, MouseLeftButtonDown, MouseLeftButtonUp, MouseRightButtonDown, MouseRightButtonUp, and the corresponding tunneling events.

Mouse類別會提供其他屬性和方法來判斷滑鼠的狀態。The Mouse class provides additional properties and methods for determining the state of the mouse.

建構函式

MouseButtonEventArgs(MouseDevice, Int32, MouseButton) MouseButtonEventArgs(MouseDevice, Int32, MouseButton) MouseButtonEventArgs(MouseDevice, Int32, MouseButton) MouseButtonEventArgs(MouseDevice, Int32, MouseButton)

使用指定的 MouseButtonEventArgs、時間戳記和 MouseDevice,初始化 MouseButton 類別的新執行個體。Initializes a new instance of the MouseButtonEventArgs class by using the specified MouseDevice, timestamp, and MouseButton.

MouseButtonEventArgs(MouseDevice, Int32, MouseButton, StylusDevice) MouseButtonEventArgs(MouseDevice, Int32, MouseButton, StylusDevice) MouseButtonEventArgs(MouseDevice, Int32, MouseButton, StylusDevice) MouseButtonEventArgs(MouseDevice, Int32, MouseButton, StylusDevice)

使用指定的 MouseButtonEventArgs、時間戳記、MouseDeviceMouseButton,初始化 StylusDevice 類別的新執行個體。Initializes a new instance of the MouseButtonEventArgs class by using the specified MouseDevice, timestamp, MouseButton, and StylusDevice. 執行個體時提供 SQL Server 登入。.

屬性

ButtonState ButtonState ButtonState ButtonState

取得與事件關聯的按鍵狀態。Gets the state of the button associated with the event.

ChangedButton ChangedButton ChangedButton ChangedButton

取得與事件關聯的按鍵。Gets the button associated with the event.

ClickCount ClickCount ClickCount ClickCount

取得按鍵被按一下的次數。Gets the number of times the button was clicked.

Device Device Device Device

取得初始化這個事件的輸入裝置。Gets the input device that initiated this event.

(Inherited from InputEventArgs)
Handled Handled Handled Handled

取得或設定值,這個值表示路由事件在傳送路由時之事件處理的目前狀態。Gets or sets a value that indicates the present state of the event handling for a routed event as it travels the route.

(Inherited from RoutedEventArgs)
LeftButton LeftButton LeftButton LeftButton

取得滑鼠左鍵的目前狀態。Gets the current state of the left mouse button.

(Inherited from MouseEventArgs)
MiddleButton MiddleButton MiddleButton MiddleButton

取得滑鼠中鍵的目前狀態。Gets the current state of the middle mouse button.

(Inherited from MouseEventArgs)
MouseDevice MouseDevice MouseDevice MouseDevice

取得與這個事件相關聯的滑鼠裝置。Gets the mouse device associated with this event.

(Inherited from MouseEventArgs)
OriginalSource OriginalSource OriginalSource OriginalSource

在父類別進行任何可能的 Source 調整之前,取得純點擊測試所判定的原始報告來源。Gets the original reporting source as determined by pure hit testing, before any possible Source adjustment by a parent class.

(Inherited from RoutedEventArgs)
RightButton RightButton RightButton RightButton

取得滑鼠右鍵的目前狀態。Gets the current state of the right mouse button.

(Inherited from MouseEventArgs)
RoutedEvent RoutedEvent RoutedEvent RoutedEvent

取得或設定與這個 RoutedEventArgs 執行個體相關聯的 RoutedEventGets or sets the RoutedEvent associated with this RoutedEventArgs instance.

(Inherited from RoutedEventArgs)
Source Source Source Source

取得或設定引發事件之物件的參考。Gets or sets a reference to the object that raised the event.

(Inherited from RoutedEventArgs)
StylusDevice StylusDevice StylusDevice StylusDevice

取得與這個事件相關聯的手寫筆裝置。Gets the stylus device associated with this event.

(Inherited from MouseEventArgs)
Timestamp Timestamp Timestamp Timestamp

取得這個事件發生的時間。Gets the time when this event occurred.

(Inherited from InputEventArgs)
XButton1 XButton1 XButton1 XButton1

取得第一個延伸的滑鼠按鍵的目前狀態。Gets the current state of the first extended mouse button.

(Inherited from MouseEventArgs)
XButton2 XButton2 XButton2 XButton2

取得第二個延伸的滑鼠按鍵的目前狀態。Gets the state of the second extended mouse button.

(Inherited from MouseEventArgs)

方法

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(Inherited from Object)
GetPosition(IInputElement) GetPosition(IInputElement) GetPosition(IInputElement) GetPosition(IInputElement)

傳回滑鼠指標相對於指定之項目的位置。Returns the position of the mouse pointer relative to the specified element.

(Inherited from MouseEventArgs)
GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
InvokeEventHandler(Delegate, Object) InvokeEventHandler(Delegate, Object) InvokeEventHandler(Delegate, Object) InvokeEventHandler(Delegate, Object)

以型別專屬的方式叫用事件處理常式,這樣做能夠提升事件系統的效率。Invokes event handlers in a type-specific way, which can increase event system efficiency.

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
OnSetSource(Object) OnSetSource(Object) OnSetSource(Object) OnSetSource(Object)

在衍生類別中覆寫時,每當執行個體的 Source 屬性值變更,便會提供通知回呼進入點。When overridden in a derived class, provides a notification callback entry point whenever the value of the Source property of an instance changes.

(Inherited from RoutedEventArgs)
ToString() ToString() ToString() ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(Inherited from Object)

適用於

另請參閱