Visual C# 1
Visual C# 1
PROGRAMMING
C# Windows Forms
• Each time you create a Windows application, Visual Studio will
display a default blank form.
• You can drag the controls onto your applications main form and adjust
their size and position.
• The first step is to start a new project and build a form.
Open your Visual Studio and select File
New Project and from the new project dialog box select Other
Languages
Visual C# and select Windows Forms Application.
Enter a project name at the bottom of the dialogue box and click
OK button.
Continue…
• After selecting Windows Forms Application, you can see a default
Form (Form1) in your new C# project.
• At the top of the form there is a title bar which displays the forms title.
• Form1 is the default name, and you can change the name to your
convenience.
• The title bar also includes the control box, which holds the minimize,
maximize, and close buttons.
• If you want to set any properties of the Form, you can use Visual
Studio Property window to change it.
• If you do not see the Properties window, on the View menu, click
Properties window.
Continue…
• To change the forms title from Form1 to MyForm, click on Form1 and
move to the right side down Properties window, set Text property to
MyForm.
• Then you can see the Title of the form is changed.
• Likewise you can set any properties of Form through Properties
window.
• You can also set the properties of the Form1 through coding.
• For coding, you should right-click the design surface or code window
and then clicking View Code.
Continue…
• For example , if you want to change the back colour of the form to
Brown , you can code in the Form1_Load event like the following.
label1.Image = Image.FromFile("C:\\testimage.jpg");
Continue…
C# Button Control
• A button is a control, which is an interactive component that enables
users to communicate with an application.
• The Button class inherits directly from the ButtonBase class.
• A Button can be clicked by using the mouse, ENTER key, or
SPACEBAR if the button has focus.
• When you want to change display text of the Button , you can change
the Text property of the button