0% found this document useful (0 votes)
6 views11 pages

Visual C# 1

The document provides a guide on creating Windows Forms applications using Visual C#. It covers the steps to start a new project, customize form properties, and utilize controls such as Labels and Buttons. Additionally, it explains how to handle events like button clicks programmatically.

Uploaded by

raagaqaran1988
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views11 pages

Visual C# 1

The document provides a guide on creating Windows Forms applications using Visual C#. It covers the steps to start a new project, customize form properties, and utilize controls such as Labels and Buttons. Additionally, it explains how to handle events like button clicks programmatically.

Uploaded by

raagaqaran1988
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

VISUAL C#

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.

private void Form1_Load(object sender, EventArgs e)


{
this.BackColor = Color.Brown;
}
C# Label Control
• Labels are one of the most frequently used C# control.
• We can use the Label control to display text in a set location on the
page.
• Label controls can also be used to add descriptive text to a Form to
provide the user with helpful information.
• The Label class is defined in the System.Windows.Forms namespace.
• To add a Label control to the form –
• Click Label in the Toolbox
• And drag it over the forms Designer and drop it in the desired
location.
Continue…
• If you want to change the display text of the Label, you have to set a
new text to the Text property of Label.

label1.Text = "This is my first Label";

• In addition to displaying text, the Label control can also display an


image using the Image property, or a combination of the ImageIndex
and ImageList properties.

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

button1.Text = "Click Here";


Calling a Button's Click Event
Programmatically
• The Click event is raised when the Button control is clicked.

• This event is commonly used when no command name is associated
with the Button control.

• Raising an event invokes the event handler through a delegate.


Continue…

You might also like