Control Handling Windows Form
Common Properties for all the controls:
The following properties commonly available for all the controls:Common Properties
Property | Description |
Name | Specifies the name of the control. |
Text | Specifies the displayable text of the control. |
BackColor | Specifies the background color of the control. |
ForeColor | Specifies the foreground color of the control. |
Font | Specifies the font style of the control‘s text. |
Enabled | Enables / Disables the control. |
Visible | Displays / Hides the control. |
Cursor | Specifies the mouse pointer style, when the mouse is over on the control at run time. |
Runtime | |
Size | Specifies the Width and Height of the control. |
Location | Specifies the X and Y co-ordinations of the control‘s position on the form. |
TextAlign | Specifies the position of the text in the control. |
Image | Specifies the image that is to be displayed in the control along with the text. |
ImageAlign | Specifies the position of the image in the control |
TabIndex | Specifies the index of the control in the tab order. |
ContentMenuStrip | Contains the reference of the respective context menu control. |
COMMON EVENTS FOR ALL THE CONTROLS:
The following events commonly available for all the controls:
COMMON EVENTS
Event | Description |
Click | Executes when the user clicks the control run time. |
DoubleClick | Executes when the user double-clicks the control at run time. |
MouseMove | Executes when the mouse pointer is moves across the control. |
MouseEnter | Executes when the mouse pointer is focused on to the control. |
MouseLeave | Executes when the mouse pointer is out of the control. |
KeyPress | Executes when any key is pressed on the keyboard, while the focus is on the control. |
Enter | Executes when the focus is entered into the control. |
Leave | Executes when the focus got out of the control. |
Event: An event is a run time action that can be performed by the user.
Let us practice the above properties and events on the button control.
Demo on Buttons
- Take a new Windows Forms Application project.
- Design the form as follows:
- To design the form as above set the following properties
- Double click on Button1 and Write the following code:
private void button1_Click(object sender, EventArgs e) { DateTime dt = DateTime.Now; MessageBox.Show(dt.ToString()); }
- Double click on Button2 and Write the following code:
private void button2_Click(object sender, EventArgs e) { Random r = new Random(); int n = r.Next(1, 500); MessageBox.Show(n.ToString()); }
- Double click on Button3 and Write the following code:
private void button3_Click(object sender, EventArgs e) { MessageBox.Show("Bye...."); Application.Exit(); }
No comments:
Post a Comment