Free Code Snippets in C#, Net Framework, Office 365, ASP.Net,WPF, Visual Studio, SQL Server, Antivirus free
#

WPF: Mouse position

 

How to determine the position of the mouse pointer in a WPF application

 

The position of the mouse is always determined relative to the upper left corner of a superimposed UIElement.

From the MouseEventArgs parameter in the Mouse_Move event, you can use .GetPosition (..) Determine the distance X and Y

 

//< mouse position >

Point mouse_point = e.GetPosition(this);

double mouse_x = mouse_point.X;

double mouse_y = mouse_point.Y;

//</ mouse position >

 

 

 

 

 

In C # Code

        private void BaseGrid_MouseMove(object sender, MouseEventArgs e)

        {

            //------------< MouseMove() >------------

            //< mouse position >

            Point mouse_point = e.GetPosition(this);

            double mouse_x = mouse_point.X;

            double mouse_y = mouse_point.Y;

            //</ mouse position >

 

            adjust_ColRow(sender, e);

            //-------------</ MouseMove() >------------

        }

 

 

Wpf, cursor, mouse, relative, UIElement, parent Control

Mobile
»
WPF / UWP: Canvas with relative positions and sizes
»
C #, WPF, UWP: ScreenShot to save an app or window area as a file
»
C #: Windows ScreenShot save as file
»
WPF Color Picker on Color Cube
»
WPF: Draw ColorWheel in C# by drawing Lines
»
WPF: Snap In to Next Lines of Elements
»
WPF Code: Usercontrol with customizable size at runtime
»
WPF: Save the background of a Windows app as a ScreenShot
»
WPF, UWP: Create transparent app window
»
WPF: Determine the relative position of an element

.

Contact for Jobs, Project Requests: raimund.popp@microsoft-programmierer.de