0% found this document useful (0 votes)
2 views

CS6004 Application Development - Lecture5

This document provides an overview of Windows Forms Applications, a GUI class library in the .NET Framework designed for desktop application development. It covers the creation of Windows Forms Apps, the differences between .NET Framework and .NET Core, and the essential components of the Visual Studio Designer Window. Key topics include project structure, control properties, events, and event handlers in Windows Forms development.

Uploaded by

kalhara wijekoon
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

CS6004 Application Development - Lecture5

This document provides an overview of Windows Forms Applications, a GUI class library in the .NET Framework designed for desktop application development. It covers the creation of Windows Forms Apps, the differences between .NET Framework and .NET Core, and the essential components of the Visual Studio Designer Window. Key topics include project structure, control properties, events, and event handlers in Windows Forms development.

Uploaded by

kalhara wijekoon
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

CS6004

Application
Development

Lecture 5

Chamila Karunatilake
[email protected]

1
Outline

• Windows Forms Applications


• .NET Desktop Development
• Windows Forms Apps
• How to Create a Windows Forms App
• Important Parts of Designer Window

2
Windows Forms Applications

• Windows Forms is a Graphical User Interface(GUI) class library which is


bundled in .Net Framework.
• Its main purpose is to provide an easier interface to develop the
applications for desktop, tablet, PCs.
• It is also termed as the WinForms.
• The applications which are developed by using Windows Forms or
WinForms are known as the Windows Forms Applications that runs on
the desktop computer.

3
Windows Forms Applications

• A Windows Forms application is an event-driven application.


• Unlike a batch program, it spends most of its time simply waiting for the
user to do something, such as fill in a text box or click a button.
• The code for the application can be written in a .NET programming
language

4
.NET Desktop Development

First, you'll create a C# application project. The project type comes with all
the template files you'll need, before you've even added anything.
• Open Visual Studio.
• On the start window, select Create a new project.
• It is possible to select one of the three types of projects from below.
– Windows Forms App
– Windows Forms App (.NET Framework)
– WPF Application

5
Static Modifier

6
Windows Forms App (.NET Framework)
• Visual Studio gives developers the option of creating projects based on
.NET Framework or .NET Core. Both have been superseded with the
release of .NET 5.
• Developers still have the option to create projects with the .NET
Framework.
• .NET Framework is older than .NET Core, and runs on Windows only.
• When .NET Core 3.0 was released, Microsoft began recommending that
new applications, regardless of what type, be developed with .NET Core.
Microsoft also announced that there would be no further major update
to the .NET Framework.

7
Windows Forms App
• With .NET 5, Windows Forms Application(.NET Core) became the
default. (Windows Forms App is .NET Core 3.0 or newer.)
• .NET Core was created to be cross-platform, and originally did not
support Windows desktop apps.
• Best practice is to choose "Windows Forms App" for new development.

8
WPF Application
• WPF stands for Windows Presentation Foundation.
• WPF is a UI framework used for developing Windows or desktop client
applications.
• It is the latest approach to the GUI framework being used with the .NET
framework.
• It has all the functionality that is being required to develop, run,
execute, manage, and handle Windows client applications.
• It generally provides holistic means for combining or integrating UI, 2D
and 3D graphics, digital media, and documents.
• It is the current platform for developing windows applications.
9
10
Important parts of Designer Window

11
Important parts of Designer Window
1. Solution Explorer
– All of your project files, code, forms, resources, will appear in this
pane.
2. Properties
– This pane shows property settings you can configure based on the
item selected.
– For example, if you select an item from Solution Explorer, you'll see
property settings related to the file.
– If you select an object in the Designer, you'll see settings for the
control or form.
12
Important parts of Designer Window
3. Form Designer
– This is the designer for the form. It's interactive and you can drag-
and-drop objects from the Toolbox.
– By selecting and moving items in the designer, you can visually
compose the user interface (UI) for your app.
4. Toolbox
– The toolbox contains all of the controls you can add to a form.
– To add a control to the current form, double-click a control or drag-
and-drop the control.

13
Important Files of the Project
• program.cs is the main of the application. This
will be executed first when the application
runs.
• Form1.cs is the code-behind file of the
windows form. It is the class file of the
windows form where the necessary methods,
functions also event driven methods and codes
are written.
• Form1.designer.cs is the designer file where
form elements are initialized. If any element is
dragged and dropped in the form window, then
that element will be automatically initialized in
14
this class.
Form1.cs [Design]

15
Form1.cs

• The "partial" keyword


indicates that the code for
a class can be found in
multiple files.
• The forms designer in
Visual Studio automatically
creates a Form1.Designer.cs
class where it puts the code
to create controls you
dragged onto the form.

16
Form1.Designer.cs

17
Program.cs

18
Project File
• The project file is an XML
document that contains
all the information and
instructions that
MSBuild needs in order
to build your project, like
the content to include,
the platform
requirements, versioning
information, web server
or database server
settings, and the tasks
that must be performed.
19
Toolbox

• The Toolbox window displays controls that you can


add to Visual Studio projects.
• To open Toolbox, choose View > Toolbox from the
menu bar, or press Ctrl+Alt+X.
• You can drag and drop different controls onto the
surface of the designer you are using and resize
and position the controls.

20
Controls

21
Controls

22
Controls

23
Controls

24
Controls

25
Controls and Properties

26
Control Properties

• A Windows Forms control inherits many properties form the base


class System.Windows.Forms.Control.
• These include properties such as Font, ForeColor, BackColor,
Bounds, ClientRectangle, DisplayRectangle, Enabled, Focused,
Height, Width, Visible, AutoSize, and many others.
• You can override inherited properties in your control as well as
define new properties.

27
Control Events

• A Windows Forms control inherits more than


sixty events from
System.Windows.Forms.Control.
• These include the Paint event, which causes a
control to be drawn, events related to
displaying a window, such as the Resize and
Layout events, and low-level mouse and
keyboard events.
• Some low-level events are synthesized by
Control into semantic events such as Click
and DoubleClick.
28
Control Events and Event Handlers

29
Control Events and Event Handlers

• An event handler is a method that is bound to an event.


When the event is raised, the code within the event
handler is executed.
• Each event handler provides two parameters that allow
you to handle the event properly.
• The first parameter, sender, provides a reference to the
object that raised the event.
• The second parameter, e, in the example, passes an
object specific to the event that is being handled.
30
Control Properties and Events

31

You might also like