Building desktop applications in .Net

Desktop applications are usually built to avail the processing power of the desktop computer and rich user-interface that can be provided when compared to a browser-based application. In the early days of Windows, it was too tedious for creating desktop applications since it was based on programming directly with Windows API (Advanced Programmer Interface).

With the current .net technology, building desktop applications is simplified to a great extent due to the facilities like graphical design programming environment with IDE(Integrated Development Environment), code generation for the layout of the user-interface specified in the form of controls in a form, rich set of base classes with the logic for the respective controls, lucid language for coding the application logic, facility to include customized controls, etc. along with the compatibility to the software designed in earlier version of Windows.

C# and are two languages used to build desktop applications in .Net. Since both of them offer the same programming environment with same set of user-interface classes and the resource editor, there is no major difference in developing a desktop application in C# or

The entire programming for desktop application in .Net is based on the concept of Windows Forms (or WinForms). It is basically an object-oriented programming model in which a desktop application can be created using the classes included in the namespace, System.Windows.Forms. Using the facility of code generation and the resource editor provided by the IDE of the Visual Studio, Windows Forms applications can be built faster and easier.

The class, Form in the System.Windows.Form namespace is used as the base class which needs to be derived to create the form in which the entire application logic resides. The entry and exit point (implemented in the Main() method) for the Windows Forms application is also within this class and hence centralized within the same class.

The events sent to the application are processed in the Application.Run () method in the Main () method of the Form class. This takes care of polling the events passed in the message queue and process them accordingly.

System.Drawing is also an important namespace that provides a facility to basic GDI+ (Graphic Design Interface) feature. This includes all the classes necessary for enhancing the functionalities for user controls like modifying the standard control for different appearance and behavior or designs a complete new custom control with user-defined features.

Building blocks for developing desktop applications

Some of the important classes used for developing desktop applications are discussed below:


Every window displayed in a desktop application is considered as form which can be of any type like typical window (main window of Single Document Interface (SDI) or Multiple Document Interface (MDI) application), modal and modeless dialog boxes, etc. By setting the properties of the form, code is automatically generated in the form by the IDE to behave as per the settings. Also, there is a provision for handling events that can occur on the form like activation, loading, resizing, etc.


These are the main components of the form on which they reside and allow the user to interact with the application. In addition to the usual type of controls like textbox, special type of controls like MonthCalender, ProgressBar, PrintDialog, FontDialog, TrackBar, etc. are provided for faster development.

By dragging and dropping of the control from the ToolBox to the form in the IDE and setting it with the required properties, the source code gets updated automatically with the necessary changes for the inclusion of the control.

Event handlers

Desktop applications are mostly event-driven due to the user interaction with the Graphical User Interface. .Net framework has catered to this requirement by providing the feature of Events and Delegates. As in any typical Windows application, every control in a form is designed to trap events and handle them in required way. Events are notifications sent to the control that may be initiated by the User (example being click of command button) while Delegates are the routines that contain the logic necessary for handling the Event. Though the Delegate is similar to the function pointer in C++, it is also object-oriented, type-safe and secure. Event provides its clients (controls) to specify the delegate that need to be called when the event occurs. The two parameters that a delegate takes are the event source (of type, Object ) and the event information (of type, EventArgs class).


Following are the three classes for building menu:

System.Windows.Forms.MainMenu – menu structure for a form
System.Windows.Forms.MenuItem – individual menu item displayed in MainMenu or ContextMenu
System.Windows.Forms.ContextMenu- shortcut menu displayed during the right click of mouse button over a control or are of the form

The IDE of the Visual Studio helps to design menus in a faster and simpler way. Code for the logic that needs to be implemented on click of menu item has to be edited in the event handler of the menu item.

Classes related to graphics

.Net framework provides the following classes related to graphics functionality. These classes help to programmatically create graphics with numerous options and included in the namespace, System.Drawing. Some of them are discussed below:

Dimension: Classes which are used for specifying dimensions are Point, Size and rectangle. They have methods for displaying the values which helps in development to a great extent.

Brush: Different types of brush classes are available to fill the interior of graphical shapes while drawing. Examples for Brushes are SolidBrush, TextureBrush, etc.

Pen: Pen object is used for drawing line and curves with selected color and thickness. It provides options for specifying the width and style of the line drawn.

Font: used for formatting the text which includes specifications for the font family, font face, size and style attributes. This helps in writing the text in the required format.

Graphics: System.Drawing.Graphics is a class used for drawing lines, curves and strings. The main advantage is that the output of the drawing can be saved in any form like jpg, bmp, etc.

Customized controls for user-defined features

Sometimes it may be necessary for designing a user-interface control which is different from those standard controls provided by the framework and need to cater to a specific data model and user interaction. For this, the framework offers the facility to design a customized control which can be derived from System.Windows.Forms.UserControl. It should be defined with the required properties for specifying its look and behavior and attributes for specifying its appearance in the Visual Studio. To specify the customized rendering logic, OnPaint method has to be overridden.

Tips for building desktop applications

• The main purpose of building the desktop application along with its design objectives like performance, scalability and security have to be identified before starting to build the application.
• Most of the desktop applications are resource intensive and hence need to share resources like CPU memory, disk I/O, network I/O, etc. By sharing resources, performance of all the other executing applications and the entire system improves better.
• Application response to the User needs to be given greater priority since User interactions are more in a desktop application when compared to that of a distributed application. For this, tasks which are time-consuming can be asynchronously executed as background tasks for which the application needs to be multithreaded and hence requires careful development.

| All about Conceptual Analysis on .NET Remoting | Building desktop applications in .Net | Building Distributed Applications Efficiently Using .Net Remoting | C# (C Sharp) Unified Type System: Reference Types | C# (C Sharp) Unified Type System: Value Types | Data access in .Net | Delegates Vs Interfaces in C# (C Sharp) | How is Integration between Java and .NET Achieved | How is Versioning Achieved in C# (C Sharp) | Implementing Authorization and authentication in | Implementing design patterns in .Net | List of Query Keywords in C# (C Sharp) |

“Amazon and the Amazon logo are trademarks of, Inc. or its affiliates.”

| Privacy Policy for | Disclosure | Contact |

Copyright - © 2004 - 2023 - All Rights Reserved.