Thursday 26 September 2013

Introduction to Windows Forms (C# .Net) programming concepts

Creating Windows Applications

Doing so is easy-you just go to start ->All programs-> Microsoft Visual Studio 2008 show in Fig -1.
Fig -1
Now open New project dialog with the New Project button in the Start page,or New Project menu item in the File menu.Then you select Visual C#.Net projects folder in Project Types box at right in this dialog, select the Windows Application icon in the Temples box,give new name & Location to application in the boxes of same names, and click OK.This is create a Windows Project and solution.


Fig- 2

Fig -3
  • A visual C# .Net project
  • Assembly info.cs
  • Form1.cs
All these files are created for us automatically by Visual C# .Net. As you see in following figures.

Fig -4

Adding Controls to Forms

In Windows, users interact with your program using controls:scroll bars,buttons,text box ,menus and so on all the user interface elements .you use the toolbox, to add controls to a form.
Fig -5

Example ->Create Calculator 

Windows application we just created, as you see in the following Figure.simple example of calculators .
Visual C# .net gives these new names automatically -Button 1 , label ,text box.

Fig -6
Note: Change the control caption using control property window press F4.

Fig -7

Handling Events

We have added two controls to our program, a button and Text Box,they don't actually do anything when the program runs.we want to display a result when the user clicks the button, so double click the button now to open the form's code designer  to this procedure show next Figure.

Fig- 8
There is four buttons control ADD,SUB,MUL and DIV. For simple calculator programming code for different buttons show fig-9,10,11.

                               
Fig -10
Fig -9

Fig-11


Finally result of ADD code snippet from above figures


0 comments:

Post a Comment