From the course: Windows Presentation Foundation: 3 Events and the Event Model

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Use the MouseMove event

Use the MouseMove event

From the course: Windows Presentation Foundation: 3 Events and the Event Model

Start my 1-month free trial

Use the MouseMove event

- Instructor] The mouse move event exists so that you can be notified when the mouse pointer is moving over a visual element on the screen. When the mouse pointer moves one pixel to the left or right or up and down over that element, the event is raised. And that means that you can get the current x and y position of the cursor on the screen and use that to update the UI on the screen, draw things on the screen, or manipulate things by moving them around based on where the mouse pointer is. For this example, I'll start by looking at main window, which has a grid and a border, we've got an image in the background. I'm also drawing some lines. One of the ways to draw a line in WPF is to use the line element. So you're going to specify a line named line1. The stroke is the color or the brush that's applied to the line. Stroke thickness is how thick the line is. And then you specify the starting point and the ending point of the line. On line 31 and 32 I'm specifying the starting point's…

Contents