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
From the course: Windows Presentation Foundation: 3 Events and the Event Model
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
The MouseEnter and MouseLeave events2m 26s
-
Use the MouseWheel event2m 55s
-
Use the MouseMove event6m 19s
-
Set the mouse cursor2m 2s
-
Start a drag operation7m 24s
-
Use DragEnter to indicate a valid drag target2m 20s
-
Use the Drop event to complete the drag/drop operation2m 34s
-
Use formats to send different data to the drop target3m 39s
-
-
-