A Blog By Bhushan Kediya
Archive for March, 2010
Adding Controls to Windows Form
Mar 5th
To add a Control to ‘form1’, first make sure that the Visual C# Toolbox is open.
You can see the toolbox to the left of ‘Form1’.
If not then Select the View à Toolbox menu item or Press Ctrl + Alt + X.
- Now simply drag a textbox from the toolbox to ‘Form1’, or just double-click the ‘Textbox’ control in the toolbox. This adds a textbox to ‘Form1’.
- Now add a button to ‘Form1’ in the same manner as shown.
Properties
- Click the button in ‘Form1’ to select it so the fuzzy outline appears around it.
- Now, move to the properties window at the lower right of the IDE. If not seen then select View à Properties Window or press F4 key.
- Click ‘Text’ Property in the properties window; change the text of the button from ‘button1’ to ‘Click Me’.
The properties window lists properties, the Property on the left & their values on the right. To change a property’s value, you only have to edit its setting and press enter.
To associate the code with button double-clicks the button, a file name ‘Form1.cs’ will open.
In it the method name:
private void button1_Click (object sender, Eventargs e)
{
}
Will see.
In this method write, textbox1.text = “JAI GAJANAN”;
Now Run the Program by Selecting Debug/start Debugging, or by pressing F5.
The application starts and when yu click the ‘Click Me’ button, the message “JAI GAJANAN” appears in the text box.
To close the application, click the close button (X) at upper right.
Visual C# has a handy way of letting you know when a file has been changed and has not been saved- an asterisk (*) will appear after the name of the file. But when compile the program it automatically saves the Code.
