Google


ADBRITE ads links
You are here: CodeIdol.com > C# > C# Cookbook, 2nd Edition > Delegates, Events, And Anonymous Methods > Tracking And Responding To The Mouse

SAVE
Digg
Shown on del.icio.us del.icio.us
See Whos Talking About This on Technorati Technorati
I've Reddit reddit

Recipe 9.11. Tracking and Responding to the Mouse

Problem

Many new mice have more than just a left and right button. Nowadays, mice come with several additional buttons and a mouse wheel. You need to allow your application to take advantage of these new mice features. Additionally, you might need to know the mouse's current location on a particular window, whether it is on the client area of the window (where your menus, toolbars, and controls are placed in the window), whether it is on the nonclient area of the window (window border, titlebar, close button, etc.), or the x and y coordinates of the mouse pointer.

Solution

Use the mouse events that are built into the System.Windows.Forms.Form class.

Discussion

Seven mouse events exist in the System.Windows.Forms.Form class. These are, in the order in which they occur:

  • MouseEnter

  • MouseMove

  • MouseHover, MouseDown, or MouseWheel

  • MouseUp (if MouseDown was the previously raised event)

  • MouseLeave

Most of these events accept a MouseEventArgs object that contains all the information about the mouse when the event is raised. The MouseEventArgs class contains the following data:

  • Which button the user is acting on

  • The number of times the mouse button was clicked

  • The direction and speed of the mouse wheel

  • The x and y coordinates of the mouse pointer

Your code can make use of any one or more of these events on the Form class along with the MouseEventArgs object.

See Also

See the "Form Class," "MouseEventArgs Class," "Control.MouseDown Event," "Con-trol.MouseEnter Event," "Control.MouseHover Event," "Control.MouseLeave Event," "Control.MouseMove Event," "Control.MouseWheel Event," "Control.MouseUp Event," and "Control.MouseMove Event" topics in the MSDN documentation.


SAVE
Digg
Shown on del.icio.us del.icio.us
See Whos Talking About This on Technorati Technorati
I've Reddit reddit

You are here: CodeIdol.com > C# > C# Cookbook, 2nd Edition > Delegates, Events, And Anonymous Methods > Tracking And Responding To The Mouse
   
Related tags







Popular Categories
Unix books and guides
AJAX popular information
C# language guides
Windows books and cookbooks
.......






© CodeIdol Labs, 2007