How to make a simple GUI program using C# and .Net Framework: Part 1

Visual C#

Hi there! In this post I guide you on how to make a simple C# program.

A little bit about C#, C#(pronounced as c-sharp) is a newer programming language developed by Microsoft as the primary language for their .Net Framework. C# aims to provide the best of C++ and Java in one platform. It is faster than Java and much more productive and easier than C++. Like Java, C# is not really a compiled language nor it is an interpreted language. C# source code are not directly compiled into machine code. Instead it is compiled into a special intermediate bytecode into which it is interpreted/recompiled by the CLR(common language runtime) compiler which is a part of .Net Framework. Because of that, a C# program can be optimized for a particular CPU at run time without the need of separate binary. .Net Framework (pronounced dot-net framework) is a collection of library that is accessible from numerous language that support .Net Framework. It’s main language is C# but it has support for C++, J# and Visual Basic .Net. The programming language must be compiled into the bytecode similar to what C# compiles into. This enable other programming language to use library built using other programming language in a very portable way. The .Net Framework is preinstalled on Windows XP service pack 2 and above. For Windows XP below SP2, user need to install .Net Framework separately. On Linux, a project called “Mono” provide a limited support for software using CLR with some compatibility issue.

In this post, we will be using Microsoft Visual C# Express edition to make our program. The express edition is free and can be downloaded from here. Microsoft Visual Studio is a collection of IDE(Integrated Development Environment) for software development. The standard license is not free although it is arguably the best IDE available.

Start Visual C# Express Edition and you should see a dash board similar to this.

Click on the new project button.

Select “Windows Forms Application” and change the project name to “MyMouseFollower” or anything you like. Press “OK” and the first screen you should see is a form builder.

The form builder is a tool that enable you to easily layout your program without coding directly. Notice on the left side of the builder, there is a “toolbox” button. Click it and you should see a collection of “Controls” that can be used for your program.

For this project we are going to use a Panel. A panel is simply an empty box. Later we will draw stuff on this Panel. Click on it and drag drop over the Form.

Also, select a Label and drag drop it just under the panel.

Notice that the text on the new label is ‘label1′ that is not what we want. Right click on it and select properties. A tab should appear on the right side of the screen.

The tab allow you to edit the properties of the selected Control. Edit the “Text” properties of label1 to “My mouse follower” or anything you like. You should see that the label’s text change from “label1″ to “My mouse follower”.

You can run the program using the “Start Debugging” button located on the top toolbar. A fully functional window should appear allthough it current form it is quite useless and boring.

Now lets do something interesting.
Continue to part 2…