Visual C# Events

EVENTS and EVENT PROCEDURES (SUBPROGRAMS)

Languages ​​such as Visual Basic and Visual C# are event-driven programming languages. For example, "subroutines" can be written for events such as when the user clicks a button, changes the text in the text box, selects a control. These subroutines are also called “event procedures (event subroutine – event procedure)”.

For example, we will frequently use the following subroutine created for button control:

Button1_Click

This name given to the subprogram also indicates when that subprogram will run.

The subroutine named button1_Click will run when the button1 object is clicked and execute the commands in it.

The most used events in object-oriented programming are:

Click : Click event. It works when the user clicks on that object.

TextChanged : It is the event of changing the text. Raised when text in a text box is changed. For example, the textBox1_TextChanged subroutine runs when the text inside textBox1 changes.

SelectedIndexChanged : Runs when the selected element in lists such as ComboBox and listBox is changed. 

CheckedChanged : Runs when the states of objects such as CheckBox and radioButton are changed.

DoubleClick : It is a double click event. It works when double-clicking the specified object. For example, the Button2_DoubleClick subroutine runs when the button2 object is double-clicked.

KeyDown : It works as soon as a key is pressed on the keyboard, that is, when the key goes down. It will continue to trigger as long as the key is down.

KeyUp : Runs when the key pressed on the keyboard is released.

KeyPress : It works when a key is pressed from the keyboard. It can be thought of as a combination of KeyDown and KeyUp events.

MouseDown : For example, it works as soon as a button is clicked with the mouse, that is, when the mouse button goes down.

MouseUp : Runs as soon as the mouse button is released.

MouseMove : Runs when the mouse is moved over a control.

MouseHover : Runs when hovering over an object with the mouse.

MouseLeave : Runs when an object is pulled with the mouse.

*Warning: In order for the KeyDown, KeyUp and KeyPress events to work, the KeyPreview property of the element to which the event is attached must have the value True. For example, if we want to use KeyDown event for Form1 object, we should set KeyPreview=True from Form1's properties.

There are many more events similar to those listed above in visual programming languages. Click the Actions button (with the lightning bolt icon) shown in the image below to see all the events that apply to an object . This button is on the Properties panel.

Projects created with the Visual Studio program have two different views, form view and code view.

The interface of the program is designed in form view. Necessary controls are placed on the form and their properties are set.

In the code view, we can see and edit the subprograms and codes of the program.

Creating a subroutine by double-clicking a control

Each control has a default event in Visual Studio, and when that control is double-clicked, the subroutine for the default event is automatically created.

For example, the default event for the button object is the Click event. Therefore, when the control named button1 on the form is double-clicked, the "button1_Click" subroutine is automatically created and code can be written in it.

Likewise, the default events and sample subroutine names of the other controls are as follows:

Control
Type

Default  Event

Name of Created Subprogram

TextBox TextChanged textBox1_TextChanged
ComboBox SelectedIndexChanged comboBox1_SelectedIndexChanged
ListBox SelectedIndexChanged listBox1_SelectedIndexChanged
CheckBox CheckedChanged checkBox1_CheckedChanged
RadioButton CheckedChanged radioButton1_CheckedChanged

 

what is event handling programming, Visual C# Events, what is textchanged, how to use it, keypress keydown, visual c# subroutine creation

EXERCISES

There are no examples related to this subject.



COMMENTS




Read 1066 times.

Online Users: 258



visual-c-sharp-events