All types of buttons raise a Click event. Depending on the button ClickMode, the click event is raised either when the button changes it's state from normal to pressed (ClickMode = Press), or when it changes its state from pressed or normal (i.e. is released - ClickMode = Release).
A button can be pressed and subsequently released in two ways:
- Keyboard - when the user presses the Space keyboard button.
- Mouse - when the user presses the Left mouse button over the button.
The example below demonstrates how to create a button and handle its click event:
Handling the Button Click Event |
Copy Code
|
---|---|
NButton button = new NButton("Click me"); button.Click += new new Function<NEventArgs>(OnButtonClick); private void OnButtonClick(NEventArgs arg1) { // Get the clicked button NButton button = (NButton)arg1.CurrentTargetNode; } |
Buttons expose a DoClick public method that can be used to generate a Click event for the button. This is useful when you need to simulate a click event for a button as if the user has clicked it using the mouse.