共用方式為


MouseEventArgs Class

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Provides data for mouse-related events that do not specifically involve mouse buttons, for example UIElement.MouseMove.

Inheritance Hierarchy

System.Object
  System.EventArgs
    System.Windows.RoutedEventArgs
      System.Windows.Input.MouseEventArgs
        System.Windows.Input.MouseButtonEventArgs
        System.Windows.Input.MouseWheelEventArgs

Namespace:  System.Windows.Input
Assembly:  System.Windows (in System.Windows.dll)

Syntax

'Declaration
Public Class MouseEventArgs _
    Inherits RoutedEventArgs
public class MouseEventArgs : RoutedEventArgs

The MouseEventArgs type exposes the following members.

Properties

  Name Description
Public propertySupported by Silverlight for Windows Phone OriginalSource Gets a reference to the object that raised the event. (Inherited from RoutedEventArgs.)
Public propertySupported by Silverlight for Windows Phone StylusDevice Gets an object that reports stylus device information, such as the collection of stylus points associated with the input.

Top

Methods

  Name Description
Public methodSupported by Silverlight for Windows Phone Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodSupported by Silverlight for Windows Phone Finalize Allows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodSupported by Silverlight for Windows Phone GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public methodSupported by Silverlight for Windows Phone GetPosition Returns the x- and y-coordinates of the mouse pointer position, optionally evaluated against a coordinate origin of a supplied UIElement.
Public methodSupported by Silverlight for Windows Phone GetType Gets the Type of the current instance. (Inherited from Object.)
Protected methodSupported by Silverlight for Windows Phone MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public methodSupported by Silverlight for Windows Phone ToString Returns a string that represents the current object. (Inherited from Object.)

Top

Remarks

This event data class is used with the following mouse events.

Note that events that specifically deal with mouse button events use a different event data class, MouseButtonEventArgs. Events that deal with the mouse wheel use MouseWheelEventArgs. MouseButtonEventArgs and MouseWheelEventArgs both derive from MouseEventArgs. Therefore, you can use the shared API (MouseEventArgs.GetPosition or MouseEventArgs.StylusDevice) for any Silverlight mouse event through event handling and the event data.

In the WPF implementation of MouseEventArgs, you could check properties to determine mouse button state even if the event was not a button-related event, and also could query for the underlying device. Neither of these features are supported in the Silverlight 5 implementation of MouseEventArgs.

The most relevant member of MouseEventArgs is GetPosition, which is a method, not a property. Particularly for a mouse button event, or for cases where the mouse is captured, it is often useful to know the exact mouse pointer position at time of the event. GetPosition returns that position relative to the Silverlight coordinate space, or optionally against the specific coordinate space of a supplied reference element.

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.