
Ch
Chapter
apter
3
3
Programming with Windows Forms
Programming with Windows Forms
Department of Software Engineering
Department of Software Engineering
Faculty of Information Technology
Faculty of Information Technology
Natural Sciences University
Natural Sciences University

Agenda
Agenda
Introduction Windows Forms
Introduction Windows Forms
How to handle events in Windows Forms
How to handle events in Windows Forms
Adding controls to forms (design-time)
Adding controls to forms (design-time)
Dynamically adding controls to Forms
Dynamically adding controls to Forms
(runtime)
(runtime)
Using Complex Controls
Using Complex Controls
Creating GUI Components
Creating GUI Components
Working with Menu
Working with Menu
Creating MDI applications with Windows
Creating MDI applications with Windows
Forms
Forms
Deploying Windows Forms Applications
Deploying Windows Forms Applications

What is Windows Forms (a.k.a.
What is Windows Forms (a.k.a.
WinForms)?
WinForms)?
Windows Forms is part of the .NET framework
Windows Forms is part of the .NET framework
core classes in System.Windows.Forms
core classes in System.Windows.Forms
namespace
namespace
design-time support in various namespaces
design-time support in various namespaces
Windows Forms provides classes for building
Windows Forms provides classes for building
UIs
UIs
e.g. custom forms, common controls, standard
e.g. custom forms, common controls, standard
dialogs
dialogs
Visual Studio .NET provides tools for using
Visual Studio .NET provides tools for using
Windows Forms
Windows Forms
templates for common starting places, and a
templates for common starting places, and a
visual designer
visual designer

Windows Forms Application Structure
Windows Forms Application Structure
A Windows Forms application has three pieces
A Windows Forms application has three pieces
the application itself
the application itself
forms in the application
forms in the application
controls on the form
controls on the form
Application
mainForm
MyForm
label1
button1
Label
“Hell…”
Button
“OK”

System.Windows.Forms.Application
System.Windows.Forms.Application
The Application class represents the application
The Application class represents the application
itself
itself
no instances (all properties and methods are static)
no instances (all properties and methods are static)
processes UI events delivered by Windows
processes UI events delivered by Windows
Run
Run,
, DoEvents
DoEvents
provides access to application environment
provides access to application environment
ExecutablePath
ExecutablePath,
, StartupPath
StartupPath
CommonAppDataPath
CommonAppDataPath,
, UserAppDataPath
UserAppDataPath
CommonAppDataRegistry
CommonAppDataRegistry,
, UserAppDataRegistry
UserAppDataRegistry
class MyApp {
public static void Main() {
MyForm form = new MyForm();
System.Windows.Forms.Application.Run(form);
}
}

