This site was last updated:Monday 13 October 2008, 11:30 GMT

Educational Community

WINDOWS IN C#
(1 vote, average: 5.00 out of 5)
Written by Christopher   
Sunday, 15 June 2008 15:12

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 (0)add comment

Write comment
quote
bold
italicize
underline
strike
url
image
quote
quote
smile
wink
laugh
grin
angry
sad
shocked
cool
tongue
kiss
cry
smaller | bigger

busy
 

User Menu

None
Become a sponsor Become a sponsor Become a sponsor Become a sponsor Become a sponsor KNOGE.com offers free video and text tutorials on various softwares also free resources to improve your economy and start making money online. THIS IS ONLY A TEST AD TO DISPLAY HOW IT MIGHT LOOK Become a sponsor Become a sponsor Become a sponsor Become a sponsor Become a sponsor Become a sponsor Become a sponsor Become a sponsor Become a sponsor Become a sponsor Become a sponsor Become a sponsor Become a sponsor Become a sponsor

Adobe InDesign CS3 - Working with objects

Objects in Adobe InDesign CS3 are the basic building block of any design that you do. In this video tutorial you will learn how to create those blocks easily in...

InDesign Videos | Christopher

Read More

Adobe InDesign CS3 - Working with Panels & More

In this Adobe InDesign CS3 video tutorial you will learn how to set keys and work with panels, you will also learn how to create customized keyboard shortcuts for optimized...

InDesign Videos | Christopher

Read More

Adobe Photoshop CS3 - Create customized rust on cars

This Adobe Photoshop CS3 video tutorial will teach you how to create your own customized rust on cars for a more grungy and perhaps dusty effect. This technique does also...

Photoshop Videos | Christopher

Read More
100%
-
+
3
Show options