Introduction to C# Windows Programming |
|
Microsoft Windows is an operating system that provides graphical objects used by people to interact with a computer. These objects, called windows, must be primarily created by a person or a company, then installed on a computer that will be used. To create one of these objects, you can use a computer language such as C++, Java, Object Pascal, Assembly, C#, etc. You can also use a programming environment to do this. One object used on the computer is usually not enough to make it particularly useful. Another approach consists of grouping various objects into an ensemble called a computer application, or a Windows application, or a computer program, or a program, or an application. All these words or expressions will be used interchangeably on this site but they mean the same thing.
The C# language provides almost everything you need to create a computer application. To create a typical program, you will use your knowledge of C# and additional new concepts we will introduce. A Windows application primarily appears as a rectangular object that occupies a portion of the screen. This type of object is under the management of the operating system: Microsoft Windows. Based on the functionality of Microsoft Windows, for an application to become useful, it must be opened. An application must have an entry point. On a C/C++ application, this entry point is a function called main. On a Win32 application, this entry point is a function called WinMain. The C# language defines this entry point with a function called Main, as you should know already from your learning C#. The Main() method of C# can be defined as void or as returning an integer value.
Windows Forms is a technique of creating computer applications based on the common language runtime (CLR). It offers a series of objects called Windows Controls or simply, controls. These controls are already created in the .NET Framework through various classes. Application programming consists of taking advantage of these controls and customizing them for a particular application. To exploit these controls and other features of the .NET Framework, there are various types of applications you can create, including graphical applications (windows), web-based applications (ASP.NET web applications), or console applications, etc. There are two broad categories of objects used in a Windows Forms application: the forms and the controls. The objects used in a Windows Forms application are stored in libraries also called assemblies. As normal libraries, these assemblies have the extension .dll (which stands for dynamic link library). In order to use one of these objects, you must know the name of the assembly in which it is stored. Then you must add a reference to that assembly in your application. To add a reference to an assembly, when compiling the program, type either /reference: or /r: followed by the name of the assembly.
A form is the most fundamental object used on an application. It is a rectangular object that uses part of the computer desktop to represent an application. A form is based on the Form class that is defined in the System.Windows.Forms namespace created in the System.Windows.Forms.dll assembly. Every GUI application you will create starts with a form. There are various techniques you can use to get a form in your application: you can programmatically and manually create a form, you can inherit a form from the Form class, you can create a form based on another form that either you or someone else created already, etc. The primary means of getting a form into an application consists of deriving one from the Form class. When compiling a program, to indicate that you want to create a Windows executable application, add the /target:winexe switch.
The form is the object that gives presence to an application. Once you have created the (primary) form of your application, you can get it ready to display on the screen. This is taken care of by the Application class equipped to start an application, process its messages or other related issues, and stop the application. The Application class provides the overloaded Run() method that can be used to start a program. One of the versions of this method takes a form as argument. This form must be the first, main or primary form of your application; it will be the first to display when the application comes up.
|
|
||
Copyright © 2004-2012, FunctionX | Next | |
|