• Skip to main content
  • Skip to primary sidebar
  • Skip to secondary sidebar
  • Skip to footer

Computer Notes

Library
    • Computer Fundamental
    • Computer Memory
    • DBMS Tutorial
    • Operating System
    • Computer Networking
    • C Programming
    • C++ Programming
    • Java Programming
    • C# Programming
    • SQL Tutorial
    • Management Tutorial
    • Computer Graphics
    • Compiler Design
    • Style Sheet
    • JavaScript Tutorial
    • Html Tutorial
    • Wordpress Tutorial
    • Python Tutorial
    • PHP Tutorial
    • JSP Tutorial
    • AngularJS Tutorial
    • Data Structures
    • E Commerce Tutorial
    • Visual Basic
    • Structs2 Tutorial
    • Digital Electronics
    • Internet Terms
    • Servlet Tutorial
    • Software Engineering
    • Interviews Questions
    • Basic Terms
    • Troubleshooting
Menu

Header Right

Home » C# » C# Windows Application

Asp.Net Execution Model

By Dinesh Thakur

When the client requests a Web page for the first time, the following set of events take place:

 

1. The client browser issues· a GET HTTP request to the server.

2. The ASP.NET parser interprets the source code.

3. If the code was not already compiled into a dynamic-link library (DLL), ASP.NET invokes the compiler.

4. Runtime loads and executes the Microsoft intermediate language (MSIL) code.

                                 ASP.NET EXECUTION MODEL . 

When the user requests the same Web page for the second time, the following set of events take place:

1. The client browser issues a GET HTTP request to the server.

2. Runtime loads and immediately executes the MSIL code that was already compiled during the user’s first access attempt.

How to Create a Web Forms in C#

By Dinesh Thakur

Web Forms consist of a combination of HTML, code, and controls that execute on a Web server that i’s running Microsoft Internet Information Services (lIS). Web Forms display a UI by generating HTML that is sent to the browser, while the supporting code and controls that run the UI stay on the Web server. This split between client-side interface and server-side code is a crucial difference between Web Forms and traditional Web pages. While a traditional Web page requires all of the code to be sent to ahd be processed at the Browser, Web Forms need to send only the interface controls to the browser ,and the page processing is kept on the server. This UI/code split increases the range of supported browsers while increasing the security and functionality of the Web page.

Web Forms are commonly referred to as ASP.NET pages or ASPX pages. Web Forms have an .aspx extension and work as the containers for the text and controls that you want to display on the browser.

ASP.NET (.aspx) pages and Active Server Pages (ASP) can coexist on the same server.

The file extension determines whether ASP or ASP.NET processes it.

Web Forms are often comprised of two separate files: the .aspx file contains the UI for the Web Form, while the .aspx.vb or .aspx.cs file, which is called a code-behind page, contains the supporting code.

When you create a new project in Visual Studio .NET, a default Web Form named WebForm1.aspx is automatically included in the project .

 

To create a new ASP.NET Web Application-project and a default Web Form you have to follow the following steps:

 

1. In Visual Studio .NET, on the Start Page, click New Project.

2. In the New Project dialog box, click ASP.NET Web Application, type the project name in the Location field, and then click OK.

                                In the New Project dialog box, click ASP.NET Web Application, type the project name in the Location field, and then click OK.

Visual Studio.NET creates a new Web application and a default Web Form that is, name WebForml.aspx. If you are expanding an existing project, you can use Solution Explorer to quickly add additional Web Forms.

                                Visual Studio.NET creates a new Web application and a default Web Form that is, name WebForml.aspx.

3. Now add the Button control from the toolbox:

                               add the Button control from the toolbox

4. Now right click on the button control and select the properties.

                               Now right click on the button control and select the properties

5. Now change the text property of the button from “Button” to “Message” or whatever you like .

 

                               the text property of the button

This will change the caption of button control from “Button” to “Message”.

 

                              change the caption of button control

6. Double click on the button control and write the following code in the Button 1_Click event.

                              Button 1_Click event

7. After saving the project you must build the project.

8. Now right click on the web form and select ”View in Browser”.

                              View in Browser

9. The output will appear looks like following figure.

                              

10. Now click on the Message button. you will see the following result.

                              

The steps to add additional Web Forms to a Web Application project:

1.In the Solution Explorer window, right-click the project name, point to Add, and then click Add Web Form. The Add New Item – Project Name dialog box opens.

2. In the Add New Item – Project Name dialog box, change the name of the Web Form, . and then click Open.

A new Web Form will be created and added to the project.

Type of Windows Forms controls

By Dinesh Thakur

A Windows Forms control is a class that derives directly or indirectly from System. Windows. Forms. Control. The following list describes common scenarios for developing Windows Forms controls.

The base class for Windows Forms controls, System.Windows.Forms.Control, provides the plumbing required for visual display in client-side Windows applications. Control provides a window handle, handles message routing, and provides mouse and keyboard events as well as many other user interface events. It provides advanced layout and has properties .specific to visual display, such as ForeColor, BackColor, Height, Width, and many others. Additionally, it provides security, threading support, and interoperability with ActiveX controls. Because so much of the infrastructure is provided by the base class,· it is relatively easy to develop your own Windows Forms. controls.

The Windows Forms controls are listed here according to general function you can find all of these controls in the ToolBox.

                 A Windows Forms control is a class that derives directly or indirectly from System. Windows. Forms. Control.

                  A Windows Forms control is a class that derives directly or indirectly from System. Windows. Forms. Control.

Explaining all of the controls present in visual studio is impossible within the scope of this book, but some· most important controls are described in the next few sections.

Button

The Windows Forms Button control allows the user to click it to perform an action. The Button control· can display both text and images. When the button is clicked, it looks as if it is being pushed in and released.

                              

Whenever the user clicks a button, the Click event handler is invoked. You place code in the Click event handler to perform any action you choose.

The text displayed on the button is contained in the Text property. ·If your text exceeds the width of the button, it will wrap to the next line. However, it will be clipped if the control cannot accommodate its overall height. The Text property can contain all. access key, which allows a user to “click” the control by pressing the ALT key with the access key. The appearance of the text is controlled by the Font property and the TextAlign property. The Button control can also display images using the Image and ImageList properties. The most basic use of a Windows Forms Button control is to run some code when the button is clicked.

Clicking a Button control also generates a number of other events, such as the MouseEnter, MouseDown, and MouseUp events. If you intend to attach event handlers for these related events, be sure that their actions do not conflict. For example, if clicking the button clears information that the user has typed in a text box, pausing the mouse pointer over the button should not display a tool tip with that now-nonexistent information.

If the user attempts to double-click the Button contr91, each click will be processed separately; that is, the control does not support the double-click event.

 

How to respond to a button click

 

To assign an action on the button control write the following code in the button’s Click event handler or double click on the button in design mode it will directly transfer you to click event handler. The code written’ in handler will display a message box which will show Button1 was clicked” message.

 

Example:

 

private void button1-click(object sender, System.EventArgs e),

{

MessageBox.show(“button1 was clicked”);

}

 

Check Box

 

The Windows Forms CheckBox control indicates whether a particular condition is on or off. It is commonly used to present a Yes/No or True/False selection to the user. You can use, check box controls in groups to display multiple choices from which the user can select one or more

                           The Windows Forms CheckBox control indicates whether a particular condition is on or off.

The check box control is similar to the radio button control in that each is used to indicate a selection that is made by the user. They differ in that only one radio button in a group can be selected at a time. With the check box control, however, any number of check ‘boxes may be selected.’

A check box may be connected to elements in a database using simple data, binding.

Multiple check boxes may be grouped using the GroupBox control This is useful for visual appearance and also for user interface design, since grouped controls can be moved around together on the form designer.

The CheckBox control has two important properties, Checked and CheckState. The

Checked property returns either true or false. The CheckState property returns either

CheckState Checked or CheckState.Unchecke1d or, if the ThreeState property is set to true, CheckState may also return CheckState in determinate. In the indeterminate state, the box is displayed with a dimmed appearance to indicate the option is unavailable.

Whenever a user clicks a Windows Forms Check Box control, the Click event occurs. You can program your application to perform some action depending- upon the state of the check box.

 

How to respond to CheckBox clicks

 

To assign an action on the CheckBox control write the following code in the CheckBox’s

Click event handler. The code written in handler of checkBox control will change Text property each time the control is clicked, indicating a checked or unchecked state.

 

private void checkBox1_click(object sender, System. EventArgs e)

{

if (checkBox1.checked)

{

checkBox1. Text + = “checked”;

}

else

{

checkBox1.Text += ” Unchecked’

}

}

 

Label

Windows Forms .Label controls are used to display text or images that cannot be edited by the user. They are used to identify objects on a form – to provide a description of what a certain control will do if clicked, for example, or to display information in response to a runtime event or process in your application. For example, you can use labels to add descriptive captions to text boxes, list boxes, combo boxes, and so on. You can also write code that changes the text displayed by a label in response to events at run time. For example, if your application takes a few minutes to process a change, you can display a processing-status message in a label.

                               Windows Forms .Label controls are used to display text or images that cannot be edited by the user.

The caption displayed in the label is contained in the Text property. The Alignment property allows you to set the alignment of the text within the label.

TextBox

Windows· Forms text boxes are used· to get input from the user or to display text. The textBox control is generally used for editable text, although it can also be made read-only. Text boxes can display multiple lines, wrap text to the size of the· control, and add basic formatting. The TextBox control provides a single format style for text displayed or entered into the control. To display multiple types of formatte4 text, use the RichTextBox control.

                                Windows• Forms text boxes are used• to get input from the user or to display text.

The text displayed by the control is contained in the Text property. By default,’ you enter up to 2048 characters in a text box. If you set the Multiline property to true, you enter up to 32 KB of text. The Text property can be set at( design time with the Properties window, at run time in code, or by user input at run time. The current contents of a text be! can be retrieved at run time by reading the Text property ..

The code below sets text in the control at run time. The InitializeMyCoutrol procedure will not execute. automatically it must be called

 

private void InitializeMycontrol()

{

I I Put some text into the contro1 first .

textBox1.Text = “Thi5 . is a TextBox control,,”;

}

 

To create a password text box

 

A password box is a Windows Forms text box that displays placeholder’ characters a user types a string.

1. Set the PasswordChar property of the TextBox control to a specific character. The PasswordChar. property specifies the character displayed in the text box. example, if you want asterisks displayed in the password box, specify * for the PasswordChar property in the Properties window. Then, regardless of what character a user types in the text box, an asterisk is displayed.

2. (Optional) set the MaxLength property. The property determines how many characters can be typed in the text box. If the maximum length is exceeded, the system, emits beep and the text does not accept any more characters. Note that you may not wish to do this’ as the maximum length of a password may be of use to hackers who are trying to guess the password.

                                 

The code below initializes a text box that will accept a string up to 14 characters long and display asterisks in place of the string. The InitializeMyControl procedure will not execute automatically; it must be called.

 

private void InitializeMycontrol()

{

II Set to no text.

textBox1.Text = “”;

II The password character is an asterisk.

textBox1~passwordchar = ‘*’;

II The control’ will allow no more than 14 characters.

textBox1.MaxLength= 14;

}

 

ComboBox

The Windows Forms ComboBox control is used to display data in a drop-down combo Box. By default, the ComboBox control appears’ in two parts: the top part is a text box allows the user to type a list item. The second part is a list box: that displays a list of item from which the user can select one.

                                The Windows Forms ComboBox control is used to display data in a drop-down combo Box.

The Selectedlndex property returns an integer value that corresponds to the selected list item. You can programmatically change the-selected item by changjng the Selectedlndex value in code; the corresponding item in the list will appear in the text box portion of the combo box. If no item is selected, the Selectedlndex value is -1. If the-first item in the list is selected, then the Selectedlndex value is o. The Selectedltem property is similar to Selectedlndex, but returns the item itself, usually a string value. The Items.Countproperty reflects the number of items in the list, and the value of the Items.Count property is always one more than the largest possible Selectedlndex value because Selectedlndex Is zero-based.

How to Create a Windows Application in C#

By Dinesh Thakur

The foundation of most solutions that involve Windows Forms is the Windows Application project. Creating one is easy within the integrated development environment (IDE).

 

To Create a Windows Application project

• On the File menu, point to New, and then select Project.

                        To Create a Windows Application project

• In the left pane, choose visual C# project, and in the right pane, choose Windows Application.

                          In the left pane, choose visual C# project, and in the right pane, choose Windows Application.

Note: In the Name box, name the project something unique to indicate the application’s purpose. In the Location box, enter the directory in which you want to save your project, or click the Browse button to· navigate to it.

 

  • The Windows Forms Designer opens, showing Form1of the project you created.

                           Windows Forms Designer opens

WINDOWS FORMS

Forms Designer is a class, and when you display an instance of the form at run time, this class is the template used to create the windows form. The framework also allows you to inherit from existing forms to add functionality or modify existing behavior. When you add a form to your project, you can choose whether it inherits from the Form· class provided by the framework, or from a form you have previously created.

Windows form uses some controls, because they inherit from the Control class.

Within a Windows Forms project, the form is the primary vehicle for user interaction. By combining different sets of controls and writing code, you can obtain information from the user and respond to it, work with existing stores of data, and query and write back to the file system and registry on the user’s local computer.

Although the form can be created entirely in the Code Editor, it is easier to use the

Windows Forms Designer to create and modify forms.

 

Adding Button Control

 

To add any control to the Form Design

 

  • Open ToolBox from the View Menu. or you can press Ctrl + Alt + X as shortcut key.
  •                            Adding Button Control

Click on the Button option and Drag a single button from ToolBox to the middle of the form then it will shows as following figure with “button1” name on the form.

                                       Adding Button Control

  • To Change the name of Button open the properties after right click on the button control.
  •                                      • To Change the name of Button open the properties after right click on the button control.
  • Change the text property from button1 to “OK”
  •                                        
  •                                          Change the text property from button1 to “OK”

You can add more controls on the form which are available in Toolbox.

 

Adding windows Form to the project

 

Your windows application may need more than just a main form. The framework makes it easy to add dialog boxes, startup screens, and other supporting forms.

 

To add a windows Form that inherits from the Form class

 

  • In the Solution Explorer, right-click your project and choose ADD, the choose Windows Form.
  •                                        In the Solution Explorer, right-click your project and choose ADD, the choose Windows Form.   

To add a windows From that inherits from a previously created form class

 

  • In the Solution Explorer, right-click your project and choose Add, then choose Inherited Form.
  •                                         To add a windows Form that inherits from the Form class

Note: You can also add a Windows Form from the Project menu.

 

Resizing Windows Form

 

There are a number of ways to specify the size of your Windows Form, including manually within the Windows Forms Designer, using the Properties window, and in code.

 

To resize a form in the Windows Forms Designer

 

1. In the Windows Forms Designer, click the form to select it.

2. Click and drag one of the right sizing handle which appear on the border of the form.

The sizing handles look like small white boxes, and the mouse pointer turns into a double-headed arrow when you point at a handle.

                                             Windows Forms Designer

Note: Pressing the ARROW keys while holding down the SHIFT key allows you to resize the form more precisely.

 

To resize a form using the Properties window

 

• In the Properties window, click the Size property and enter values for the width and height, separated by a comma.

                                              To resize a form using the Properties window

Note : Expand the Size property to enter the Width and Height values individually .

Additionally, forms can be resized at run time. For example, if a form displays a bitmap, you may want to resize the form whenever the user selects a new bitmap.

 

To resize a form programmatically

 

• Define the size of a form at run time by setting the Size property of the form. The. following example shows the form size set to 100 by 100 pixels:

 

Form1.Size = new system.Drawing.Size(100, 100);

 

To change form width and height programmatically

 

• Once the Size object is defined, change either its Width or Height property. In the example below, the width of the form is set to 300 pixels from the left edge of the form, while the height stays constant .

 

Form1. width = 300;

 

• Change Width or Height by setting the Size property. As the following code snows, however, this approach is more cumbersome than simply setting Width or Height properties.

 

Form1.size = new Size(300, Form1.Size.Height);

Windows Application Developement in C#

By Dinesh Thakur

An important part of Visual Studio .NET is the ability to create Windows applications that run locally on users’ machines. Visual Studio .NET allows you to create the application and user interface using Windows Forms.

A Visual Studio Windows application is built around the .NET Framework, a rich set of classes that allows you to program sophisticated applications. You can create, Windows applications using any .NET programming language (Visual Basic, C#” Managed Extension for C++, and many others) and .NET debugging facilities.

Windows applications created with .NET classes afford you other benefits. You can access operating-system services and take advantage of other· benefits provided by your user’s computing environment. You can access data from database using ADO.NET. The GDI+ allows.’ you to do advanced drawing and painting within your windows forms.

Visual Studio .NET provides you an environment to create Windows applications .The advantage of using Visual Studio .NET is that it provides tools that make application development much faster, easier, and more reliable. These tools include:

• Visual designers for Windows Forms with drag-and-drop controls.

• Code-aware editors that include statement completion, syntax checking, and other

IntelliSense features.

• Integrated compilation and debugging.

• Project management facilities for creating and managing application files, including deployment locally, over an intranet or over the ·Internet.

If you have used Visual Studio before, these features will seem familiar; they are similar to features available in previous versions of Visual· Basic and Visual C++. Visual Studio .NET expands on these features to provide a superior environment for developing Windows applications.

WINDOWS APPLICATIONS DEVELOPMENT

Windows application development with Visual Studio can take many shapes. You can create Windows Forms and Windows service applications that leverage the power of the .NET Framework, or you can use ‘Visual C++ to create Win32 applications.

Windows Forms

A form is a bit of screen real estate, usually rectangular, that you can .use to present information to the user ad to accept input .from the user. Forms can be standard windows, multiple. document interface (MDI) windows, dialog boxes, or display surfaces for graphical routines. The easiest way to define the user interface for a form is to place controls on its surface. Forms are objects that expose properties which define their appearance, methods which define their behavior, and events which define their interaction with the user. By setting the properties of the form and writing code to respond to its events, you customize the object to meet the requirements of your application.

Windows Service Applications

Using Microsoft Visual Studio .NET or the Microsoft .NET Framework SDK, you can easily create services by creating an application that is installed as a service. This type of application is called a Windows service. With framework features, you can create services, install them, and start, stop, and otherwise control their behavior.

Win32 Projects

You can use the Project Wizard to create Win32 project types, including console applications, executable Windows applications, dynamic-link libraries, and static libraries.

Primary Sidebar

C# Tutorials

C# Tutorials

  • C# - .NET Languages Types
  • C# - Dot Net
  • C# - Dot Net Framework
  • C# - Inheritance Types
  • C# - Features
  • C# - CTS
  • C# - CLS
  • C# - CLR
  • C# - Console
  • C# - MSIL
  • C# - Base Class Library
  • C# - Web Forms Creation
  • C# - C# Vs C++
  • C# - Statements Types
  • C# - JIT
  • C# - CLI
  • C# - Controls Types
  • C# - String Types
  • C# - Execution Model

Other Links

  • C# - PDF Version

Footer

Basic Course

  • Computer Fundamental
  • Computer Networking
  • Operating System
  • Database System
  • Computer Graphics
  • Management System
  • Software Engineering
  • Digital Electronics
  • Electronic Commerce
  • Compiler Design
  • Troubleshooting

Programming

  • Java Programming
  • Structured Query (SQL)
  • C Programming
  • C++ Programming
  • Visual Basic
  • Data Structures
  • Struts 2
  • Java Servlet
  • C# Programming
  • Basic Terms
  • Interviews

World Wide Web

  • Internet
  • Java Script
  • HTML Language
  • Cascading Style Sheet
  • Java Server Pages
  • Wordpress
  • PHP
  • Python Tutorial
  • AngularJS
  • Troubleshooting

 About Us |  Contact Us |  FAQ

Dinesh Thakur is a Technology Columinist and founder of Computer Notes.

Copyright © 2025. All Rights Reserved.

APPLY FOR ONLINE JOB IN BIGGEST CRYPTO COMPANIES
APPLY NOW