Text Size

WINDOWS IN C#

(1 vote, average: 5.00 out of 5)

INTRODUCTION

A C# program can be written either in a text editor or in an integrated development environment (IDE). The later provides access to various other features. In this tutorial we examine the Visual Studio 2008 IDE in order to illustrate various concepts of a C#  windows program.

CREATING A VISUAL C# PROGRAM

When you run the visual studio 2008 you should see an image similar to image1.

Image 1. Appearance of the Visual studio 2008 IDE.

Visual studio supports many programming languages. We need to define that we want to start a project in visual C#. This project is not restricted to a visual program but it can also be a windows service, a windows library, a windows presentation foundation program, a web application, an office or outlook add-in and various other projects. In this tutorial we will create a simple windows forms program. Go to file -> new project and create a new windows forms application as illustrated in image 2.

Image 2.  New windows forms project in C#

After a while the working environment appears. We can distinguish the toolbox, the basic form, the properties window and the solution explorer. The form is the default form that will appear when the program runs. You can debug a program either by pressing F5 or by clicking on debug -> start debugging. Press F5 and see what happens. A blank form appears. Close the form so that we can continue with our programming. Click once on the form. Go to the down right section of the screen and find the properties window. Change the text property to “myFirstForm” and the FormBorderStyle to “Fixed3D”. Finally, set the property  MaximizeBox to  false. Press F5 again and see what changed. The form’s text is now the one specified in the text property, the maximize box is disabled and we cannot alter the size of the form. Next we will add some controls on the form and see their basic usage.

 

 

 

 

 

 

 

 

ADDING CONTROLS

To add control on a form you can either write code for it, or import a control from the toolbox on your right. The toolbox contains almost everything that you need to make a user-friendly windows program. Go to the Common Controls of the toolbox and double click on the button  control and on the label control. The two objects appear on the form. Change the text property of the controls to the ones shown in image 3. Also, from the font property of the label control change the font’s size to 12.

 

 

Image 3. A windows form.

ADDING CODE

We now want to make form actually do something By double-clicking on the  button control we can see some code. It automatically creates a method that is triggered when the button is pressed. You can understand this by the name of the method:

private void button1_Click(object sender, EventArgs e)

        {

 

        }

Whatever we write here will execute when this button is pressed. We will change the label’s text property to something else. Properties of controls can change either by pure code or by the properties window. Actually, the properties window just adds the necessary code to our project. To use a control’s property you use the template : Control_Name.Property = Value which in our case is:

 

        private void button1_Click(object sender, EventArgs e)

        {

            label1.Text = "Hello World!!";

 

        }

Run the project and see what we have accomplished. When the button is pressed, the label changes text. Try replacing the label with a textbox using similar code to the one presented here.

 

Trackback(0)
Comments (1)add comment

Joe said:

0
...
I have never used Visual Studio or .NET before - now thanks to this I know a litle bit about it! Good work mate!
 
February 04, 2009
Votes: +0

Write comment

busy

Site Statistics

Stats
Total Members
: 208
Total Discussion
: 0
Total Albums
: 0
Total Photos
: 0
Total Bulletins
: 0
Total Activities
: 1
Total Wall Posts
: 1