Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
50 views6 pages

Mouse Properties

The document provides examples of properties, events, and methods related to mouse interaction in Windows Forms, including how to handle mouse clicks, movements, and button states. It explains key components such as MouseEventArgs for mouse-specific events and EventArgs for general events. Additionally, it highlights the importance of the SystemInformation class for accessing mouse settings and behavior.

Uploaded by

Ahmed Al-nasheri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views6 pages

Mouse Properties

The document provides examples of properties, events, and methods related to mouse interaction in Windows Forms, including how to handle mouse clicks, movements, and button states. It explains key components such as MouseEventArgs for mouse-specific events and EventArgs for general events. Additionally, it highlights the importance of the SystemInformation class for accessing mouse settings and behavior.

Uploaded by

Ahmed Al-nasheri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Mouse Properties, Events, and Methods Examples

Here are some examples of properties, events, and methods related to mouse interaction in Windows
Forms:

Properties:

1. Cursor: Gets or sets the cursor that is displayed when the mouse pointer is over the control.

this.Cursor = Cursors.Hand; // Set the cursor to a hand icon

2. MouseButtons: Gets the current state of the mouse buttons.

if (MouseButtons.Left == MouseButtons) // Check if the left mouse button is pressed

// Handle left mouse button click

3. MousePosition: Gets the current position of the mouse pointer relative to the screen.

Point mousePosition = MousePosition; // Get the current mouse position

Events:

1. MouseClick: Occurs when the control is clicked with the mouse.

button1.MouseClick += Button1_MouseClick;

private void Button1_MouseClick(object sender, MouseEventArgs e)

// Handle the mouse click event

2. MouseEnter: Occurs when the mouse pointer enters the control.

button1.MouseEnter += Button1_MouseEnter;

private void Button1_MouseEnter(object sender, EventArgs e)

// Handle the mouse enter event

Dr. Ahmed Alnasheri 1/6


Methods:

1. Capture: Captures the mouse to receive mouse events even when the mouse pointer is outside
the control.

button1.Capture = true; // Capture the mouse to receive events

2. GetChildAtPoint: Retrieves the child control at a specified location.

Control childControl = GetChildAtPoint(new Point(10, 10)); // Get the child control at a specific

location

3. Hide: Hides the control and its child controls from the user.

button1.Hide(); // Hide the button control

These are just a few examples of properties, events, and methods related to mouse interaction in
Windows Forms. You can explore the full range of options available in the documentation or by using
IntelliSense in your development environment to discover more capabilities and tailor them to your
specific requirements.

Here are some more properties, events, and methods related to mouse interaction in Windows Forms:

Properties:

1. DoubleClickTime: Gets or sets the maximum amount of time allowed between two consecutive
clicks to be considered a double-click.

int doubleClickTime = SystemInformation.DoubleClickTime; // Get the double-click time in

milliseconds

2. MouseButtonsSwapped: Gets a value indicating whether the left and right mouse buttons are
swapped.

bool mouseButtonsSwapped = SystemInformation.MouseButtonsSwapped; // Check if the


mouse buttons are swapped

Events:

1. MouseMove: Occurs when the mouse pointer is moved over the control.

button1.MouseMove += Button1_MouseMove;

private void Button1_MouseMove(object sender, MouseEventArgs e)

// Handle the mouse move event

2. MouseLeave: Occurs when the mouse pointer leaves the control.

Dr. Ahmed Alnasheri 2/6


button1.MouseLeave += Button1_MouseLeave;

private void Button1_MouseLeave(object sender, EventArgs e)

// Handle the mouse leave event

Methods:

1. SendMouseWheel: Sends a mouse wheel message to the control at the specified location.

button1.SendMouseWheel(120); // Send a mouse wheel message with a positive delta value

2. Capture: Releases the mouse capture from the control.

button1.Capture = false; // Release the mouse capture from the button control

3. Show: Displays the control to the user.

button1.Show(); // Show the button control

These additional properties, events, and methods provide further control and flexibility for handling
mouse interactions in Windows Forms. You can explore their usage and adapt them to suit your specific
application requirements. Additionally, the SystemInformation class provides useful properties related to
mouse settings and behavior that you can leverage in your application.

Here are some more properties, events, and methods related to mouse interaction in Windows Forms:

Properties:

1. MouseWheel: Gets a value indicating the amount that the mouse wheel has been rotated.

int mouseWheelDelta = e.Delta; // Get the amount that the mouse wheel has been rotated

2. MouseHoverSize: Gets the size of the hover rectangle for the control.

Size hoverSize = SystemInformation.MouseHoverSize; // Get the size of the hover rectangle

Events:

1. MouseDown: Occurs when a mouse button is pressed while the pointer is over the control.

button1.MouseDown += Button1_MouseDown;

private void Button1_MouseDown(object sender, MouseEventArgs e)

// Handle the mouse down event

2. MouseUp: Occurs when a mouse button is released while the pointer is over the control.

Dr. Ahmed Alnasheri 3/6


button1.MouseUp += Button1_MouseUp;

private void Button1_MouseUp(object sender, MouseEventArgs e)

// Handle the mouse up event

Methods:

1. GetChildAtPoint: Retrieves the child control at the specified location.

Control childControl = GetChildAtPoint(new Point(10, 10)); // Get the child control at a specific

location

2. PointToClient: Converts the screen coordinates of a point to client coordinates.

Point clientPoint = button1.PointToClient(new Point(100, 100)); // Convert screen coordinates to


client coordinates

3. PointToScreen: Converts the client coordinates of a point to screen coordinates.

Point screenPoint = button1.PointToScreen(new Point(10, 10)); // Convert client coordinates to


screen coordinates

These additional properties, events, and methods provide further control and functionality for handling
mouse interactions in Windows Forms. You can explore their usage and adapt them to suit your specific
application requirements. The SystemInformation class also provides various properties related to mouse
settings and behavior that you can leverage in your application.

Here are some more properties, events, and methods related to mouse interaction in Windows Forms:

Properties:

1. MouseButtons: Gets the current state of the mouse buttons.

if (MouseButtons.Left == MouseButtons) // Check if the left mouse button is pressed

// Handle left mouse button click

2. MousePosition: Gets the current position of the mouse pointer relative to the screen.

Point mousePosition = MousePosition; // Get the current mouse position

Events:

1. MouseClick: Occurs when the control is clicked with the mouse.

Dr. Ahmed Alnasheri 4/6


button1.MouseClick += Button1_MouseClick;

private void Button1_MouseClick(object sender, MouseEventArgs e)

// Handle the mouse click event

2. MouseEnter: Occurs when the mouse pointer enters the control.

button1.MouseEnter += Button1_MouseEnter;

private void Button1_MouseEnter(object sender, EventArgs e)

// Handle the mouse enter event

Methods:

1. Capture: Captures the mouse to receive mouse events even when the mouse pointer is outside
the control.

button1.Capture = true; // Capture the mouse to receive events

2. Hide: Hides the control and its child controls from the user.

button1.Hide(); // Hide the button control

3. GetChildAtPoint: Retrieves the child control at a specified location.

Control childControl = GetChildAtPoint(new Point(10, 10)); // Get the child control at a specific

location

These are additional properties, events, and methods related to mouse interaction in Windows Forms.
You can explore their usage and adapt them to suit your specific application requirements. Mouse
properties, events, and methods provide you with control and flexibility when it comes to handling user
interactions with the mouse in your Windows Forms application.

Certainly! In Windows Forms, there are two commonly used event argument classes related to mouse
interaction: MouseEventArgs and EventArgs. Here's an explanation of each:

MouseEventArgs:
MouseEventArgs is an event argument class specifically designed for mouse-related events. It provides
information about the mouse event, such as the mouse button that was pressed or released, the current
position of the mouse pointer, and the amount of wheel rotation (if applicable). Some important
properties of the MouseEventArgs class include:

1. Button: Gets the mouse button that caused the event.

Dr. Ahmed Alnasheri 5/6


if (e.Button == MouseButtons.Left) // Check if the left mouse button caused the event

// Handle left mouse button event

2. Location: Gets the location of the mouse pointer relative to the control that raised the event.

Point mouseLocation = e.Location; // Get the mouse location relative to the control

3. Delta: Gets a signed count of the number of detents the mouse wheel has rotated.

int wheelDelta = e.Delta; // Get the amount of wheel rotation

EventArgs:
EventArgs is a general-purpose event argument class that doesn't provide specific information about
mouse events. It's typically used for events that don't require detailed mouse-related information. Some
events, such as MouseEnter and MouseLeave, don't require specific mouse data and
use EventArgs instead. Here's an example:

private void Control_MouseEnter(object sender, EventArgs e)

// Handle mouse enter event

In this case, EventArgs doesn't provide any mouse-specific properties and is used to indicate that the
event has occurred without additional mouse-related details.

It's important to note that the specific event argument class used depends on the event being handled.
Mouse-related events typically use MouseEventArgs to provide specific mouse information, while other
events may use EventArgs for more general purposes.

Dr. Ahmed Alnasheri 6/6

You might also like