1
UIT-VNUHCM
Lập trình môi trường Windows
LẬP TRÌNH MÔI TRƯỜNG
WINDOW
ThS. NGUYỄN THỊ THANH TRÚC
TRƯỜNG ĐẠI HỌC CÔNG NGHỆ THÔNG TIN
KHOA CÔNG NGHỆ PHẦN MỀM
Chương 3:LẬP TRÌNH GUI
2
UIT-VNUHCM
Lập trình môi trường Windows
Nội dung
Các control cơ bản trong window form
Các Dialog
Cách tạo Menu
Tạo window Form &
Mô tả các đặc tính của Window Form
3
UIT-VNUHCM
Lập trình môi trường Windows
1.FORM
4
UIT-VNUHCM
Lập trình môi trường Windows
Giao diện người dùng cung cấp phương tiện để
người dùng có thể tương tác được với chương trình
ứng dụng.
Có hai loại giao diện người dùng:
Cũng có thể kế thừa từ các window form có sẵn,
rồi thêm vào các tính năng mới.
Window Form
6
UIT-VNUHCM
Lập trình môi trường Windows
Hình sau đây là ví dụ về giao diện một cửa sổ đăng
nhập:
Window form
7
UIT-VNUHCM
Lập trình môi trường Windows
Visual Studio .Net
controls
designer
Properties,
events
8
UIT-VNUHCM
Lập trình môi trường Windows
8
9
UIT-VNUHCM
Lập trình môi trường Windows
Project Add Reference
10
UIT-VNUHCM
Bảo thành phần(component) thực hiện việc nào đó
Ví dụ Button1.Show( )
Events (Sự kiện)
Như hàm được gọi (callback function)
Nhận thông báo từ thành phần
Ví dụ Button1.Click(e)
12
UIT-VNUHCM
Lập trình môi trường Windows
Ví dụ 1
class Program
{
static void Main(string[] args)
{
Form f = new Form();
Application.Run(f);
}
}
13
UIT-VNUHCM
Lập trình môi trường Windows
Ví dụ 2
class Program
{
static void Main(string[] args)
Button
Form
Label
GUI Internal structure
containers
Panel
Button
Form
Label
16
UIT-VNUHCM
Lập trình môi trường Windows
Form Properties
Thuộc tính Kiểu Mô tả
FormBorderStyle FormBorderStyle:
FixedDialog,
Fixed3D…
Kiểu đường viền
ControlBox bool Có system menu box?
MaximizeBox bool
MinimizeBox bool
Icon Icon
ShowInTaskBar bool
StartPosition FormStartPosition
17
UIT-VNUHCM
Lập trình môi trường Windows
Form Properties
Thuộc tính Kiểu Mô tả
SizeGripStyle SizeGripStyle: Show, Hide…
WindowsDefaultLocation
20
UIT-VNUHCM
Lập trình môi trường Windows
Application class
Exit Stops all running message loops and closes all windows in the
application. Note that this may not force the application to exit
Run Starts a standard message loop on the current thread. If a
Form is given, also makes that form visible.
DoEvents Processes any Windows messages currently in the message
queue.
21
UIT-VNUHCM
Lập trình môi trường Windows
Form Method
Show()
ShowDialog();
Hide();
Close();
22
UIT-VNUHCM
Lập trình môi trường Windows
Cơ chế hoạt động Form
23
UIT-VNUHCM
Lập trình môi trường Windows
User
Event Handler:
{
Get N1 and N2
Return N1+N2
Call the program
}
Program:
Put N1+N2
25
UIT-VNUHCM
Lập trình môi trường Windows
Button
Event
Handler
Call me when you
are pressed
Button
Event
Handler
I have been pressed
GUI Control
Handler 1
Handler 2
Handler 3
GUI Control
GUI Control
Handler