

Windows provides methods you can call to simulate mouse movements and clicks such as User32.dll SendInput and User32.dll SetCursorPos. InvokeOnClick(CheckBox1, EventArgs.Empty) Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click InvokeOnClick(checkBox1, EventArgs.Empty) private void button1_Click(object sender, EventArgs e)
Prisma app for deskto[ code#
This is a protected method that can only be called from within the form or a derived custom control.įor example, the following code clicks a checkbox from button1. With a form a custom control, use the InvokeOnClick method to simulate a mouse click.

Both the and controls implement this interface. The interface provides the PerformClick method which simulates a click on the control. Some controls, such as a combobox, don't do anything special when clicked and simulating a click has no effect on the control. NET) Invoke a clickĬonsidering most controls do something when clicked, like a button calling user code, or checkbox change its checked state, Windows Forms provides an easy way to trigger the click. These protected methods are available to simulate mouse events.įor more information about these events, see Using mouse events (Windows Forms. For example, if you wanted to simulate hovering over an item in a ListBox, OnMouseMove and the ListBox doesn't visually react with a highlighted item under the cursor. The disadvantage to using a method such as OnMouseMove is that it doesn't actually control the mouse or interact with the control, it simply raises the associated event. This option is only possible within custom controls or forms, because these methods are protected and can't be accessed from outside the context of the control or form. Most events have a corresponding method that invokes them, named in the pattern of On followed by EventName, such as OnMouseMove.
