Chapter 3
Programming with Windows Forms
Department of Software Engineering
Faculty of Information Technology
Natural Sciences University
Agenda
Introduction Windows Forms
How to handle events in Windows Forms
Adding controls to forms (design-time)
Dynamically adding controls to Forms
(runtime)
Using Complex Controls
Creating GUI Components
Working with Menu
Creating MDI applications with Windows
Forms
Deploying Windows Forms Applications
What is Windows Forms (a.k.a.
WinForms)?
Windows Forms is part of the .NET framework
core classes in System.Windows.Forms
namespace
design-time support in various namespaces
Windows Forms provides classes for building
UIs
e.g. custom forms, common controls, standard
dialogs
Visual Studio .NET provides tools for using
Windows Forms
templates for common starting places, and a
visual designer
Windows Forms Application Structure
A Windows Forms application has three pieces
the application itself
forms in the application
controls on the form
Application
mainForm
MyForm
Label
label1
“Hell…”
button1
Button
“OK”
System.Windows.Forms.Application
The Application class represents the application
itself
no instances (all properties and methods are static)
processes UI events delivered by Windows
Run, DoEvents
provides access to application environment
ExecutablePath, StartupPath
CommonAppDataPath, UserAppDataPath
CommonAppDataRegistry, UserAppDataRegistry
class MyApp {
public static void Main() {
MyForm form = new MyForm();
System.Windows.Forms.Application.Run(form);
}
}
Deploying Windows Forms
Applications (cont)
Creating a Windows Installer Package
Setup project properties
File Installation Management
Registry Settings Management
File Types Management
User Interface Management
Custom Actions Management
Launch Condition Management
References
www.msdn.microsoft.com
MS Press Microsoft Visual C Sharp Dot NET
Step By Step Version.2003 - l-mcs301-200311-25
Sams Teach Yourself
Visual.Studio.Dot.Net.2003.In.21Days - lstdn02-2003-7-11.rar
FTP:
172.29.22.45
Username: sv
Password: sv
Directory: dotNET