Académique Documents
Professionnel Documents
Culture Documents
Microsoft 2
“The main difference between the web based application and
window based application is that the web application can be
access from anywhere in the world through the internet whereas
window based application need to be install on your machine to
access.
Microsoft 3
• GUI apps are based on the notion of forms and controls…
– a form represents a window
– a form contains 0 or more controls
– a control interacts with the user
Microsoft 4
• Idea is very simple:
– individual user actions are translated into “events”
– events are passed, 1 by 1, to application for processing
GUI App
Microsoft 5
GUI = Graphical User Interface
Allows the user to interact visually with a program
This is the “make it pretty” part
Microsoft 6
GUI-based events
• Mouse move
• Mouse click
• Mouse double-click
• Key press
• Button click
• Menu selection
• Change in focus
• Window activation
• etc.
Microsoft 7
Code-behind
Microsoft 8
Call-backs
Microsoft 9
Working with Visual Studio
Microsoft 10
Visual Studio .Net
designer
controls
Properties
events
Microsoft 11
Visual Studio .NET (VS.NET)
Microsoft 12
Basic operation
break
Microsoft 13
Step 1
Microsoft 14
Step 2 — GUI design
Microsoft 15
GUI design cont’d…
• A simple calculator:
Microsoft 16
Step 3 — code design
Microsoft 17
Step 4 — run mode
• Run!
Microsoft 18
Break mode?
Microsoft 19
WinForms
Microsoft 20
Abstraction
instance of
object System.Windows.Forms.Form
FCL class
CLR
Windows OS
Microsoft 21
Form properties
Form1 form;
– AutoScroll form = new Form1();
form.WindowState = FormWindowState.Maximized;
– BackgroundImage form.Show();
– ControlBox
– FormBorderStyle (sizable?)
– Icon
– Location
– Size
– StartPosition
– Text (i.e. window's caption)
– WindowState (minimized, maximized, normal)
Microsoft 22
Form methods
form.Hide();
.
• Actions you can perform on a form: .
.
form.Show();
– Activate: give this form the focus
– Close: close & release associated resources
– Hide: hide, but retain resources to show form later
– Refresh: redraw
– Show: make form visible on the screen, & activate
– ShowDialog: show modally
Microsoft 23
Form events
Microsoft 24
Example
Microsoft 25
Controls
– labels
– buttons
– text boxes
– menus
– list & combo boxes
– option buttons
– check boxes
– etc.
Microsoft 26
Toolbox
Microsoft 27
Properties and Methods for GUI Controls
Enable
Font
Text
Visible
Example methods:
Hide
Select
Show
Microsoft 28
29
Microsoft 29
Naming Controls
Microsoft 30
Conventions for Naming Controls - Start the
control name with...
• Control • Begin name with
– Button – btn
– TextBox – txt
– ListBox – lbox
– Label – lbl
– SaveFileDialog – sfd
Microsoft 31
Abstraction
object
object
object
object
Microsoft 32
Who creates all these objects?
Microsoft 33
Naming conventions
Microsoft 34
Labels
• Interesting properties:
– Text: what user sees
– Font: how he/she sees it
Microsoft 35
Command buttons
• Interesting properties:
– Text: what user sees
– Font: how he/she sees it
– Enabled: can it be clicked
• Interesting events:
– Click: occurs when button is "pressed"
Microsoft 37
Text box properties
• Basic properties:
– Text: denotes the entire contents of text box (a string)
– Modified: has text been modified by user? (True / False)
– ReadOnly: set if you want user to view text, but not modify
Microsoft 38
Text box events
• Interesting events:
– Enter, Leave: occurs on change in focus
– KeyPress: occurs on ascii keypress
– KeyDown, KeyUp: occurs on any key combination
– TextChanged: occurs whenever text is modified
Microsoft 39
List Boxes
Customer[] customers;
.
. // create & fill array with objects...
.
Microsoft 41
41
GroupBox
Microsoft 42
42
Panels
• A panel is like a group box but does not have a text label
• It contains a group of controls just like group box
– BorderStyle – get/set border style as
• BorderStyle.Fixed3D
• BorderStyle.FixedSingle
• BorderStyle.None
Microsoft 43
43
Radio Buttons
Microsoft 44
44
Radio Buttons
– * see TextBoxDemo
Microsoft 45
45
TextBox
Microsoft 46
46
TextBox
Microsoft 47
47
File Dialog
Microsoft 48
48
File Dialog
Microsoft 49
49
File Dialog
if (openDialog.ShowDialog() == DialogResult.OK) {
Image img =
Image.FromFile(openDialog.FileName);
pictureBox1.Image = img;
}
• * see ImageViewer
Microsoft 50
50
Image Class
Microsoft 51
51
PictureBox Class
Microsoft 52
52
ToolTips
• These are the small pop-up boxes which explain the purpose
of a control
• To use
– Create a new tooltip in the designer
– Drop the tooltip onto the form
– The tooltip will appear on a tray below the form
• * see ImageViewer
Microsoft 53
53
ToolTips
Microsoft 54
54
ToolTips
Microsoft 55
55
NumericUpDown
Microsoft 56
56
MonthCalendar
Microsoft 57
57
DateTimePicker
Microsoft 58
58
System.DateTime Structure
Microsoft 59
59
DateTime
Microsoft 60
60
DateTime
Microsoft 61
61
DateTime
– TimeSpan Subtract(DateTime)
– int CompareTo(DateTime)
– static DateTime Parse(string)
– ToLongDateString()
– ToShortDateString()
– ToLongTimeString()
– ToShortTimeString()
Microsoft 62
62
ListBox
Microsoft 63
63
ListBox
Microsoft 64
64
ListBox
Microsoft 65
65
Populating a ListBox
Microsoft 66
66
ComboBox
Microsoft 67
67
ComboBox
• DropDownStyle –
– Simple – text is editable & list always visible
– DropDown – default indicating text is editable & user must click
to see list
– DropDownList – value is not editable & user must click to
see list
• Items – the collection of items in the list
Microsoft 68
68
ComboBox
Microsoft 69
69
Help menu
Command Description
How Do I? Contains links to relevant topics, including how to
upgrade programs and learn more about web
services, architecture and design, files and I/O,
data, debugging and more.
Search Finds help articles based on search keywords.
Index Displays an alphabetized list of topics.
Contents Displays a categorized table of contents in which
help articles are organized by topic.
Microsoft 70
Event Handling
Microsoft 71
• The following code is for a button named btnQuit
– Function: When the button is clicked, the form closes
Microsoft 72
73
Microsoft 73
Summary
Microsoft 74
The End
Microsoft 75