Copyright © Wondershare Software
- Nguyễn Minh Đạo
Copyright © Wondershare Software
Copyright © Wondershare Software
• 1. Khởi động
– Bước 1: Khởi động Visual Studio 2008
– Bước 2: Vào menu File | New | Project
– Bước 3: Khai báo
• Khung Project types : chọn Visual C#
• Khung Templates : chọn Windows Form Application
• Khung Name: Nhập tên HelloWorld
• Khung Location : chọn ổ đĩa C:\
– Click OK.
Copyright © Wondershare Software
Copyright © Wondershare Software
Copyright © Wondershare Software
Copyright © Wondershare Software
• a. Thêm một Form mới vào Project:
– Bước1: Vào menu Project | Add New Item …
Hoặc chọn công cụ Add New Item trên thanh Standard
– Bước 2: Khai báo
• + Categories: chọn Windows Forms
• + Templates: chọn Windows Form
• + Name: đặt tên Form
– Bước 3: Nhắp Add
Copyright © Wondershare Software
• b. Thêm một Form có sẵn vào Project:
– Bước 1. Vào menu Project | Add Existing Item …
– Bước 2. Chọn Form. Nhập tên form cần thêm
– Bước 3. Nhắp Add
• c. Xóa bỏ một Form đang có trong Project:
– Bước 1. Chọn Form cần gỡ bỏ (ở cửa sổ Solution
Explorer)
– Bước 2. Vào menu Edit | Delete
• d. Lưu Form
– Vào menu File | Save Form.cs hoặc Ctrl + S
Copyright © Wondershare Software
• Bước 1: Thiết kế giao diện
– Dựa theo bài toán chọn lựa các Windows Controls thích
hợp.
– Đặt các thuộc tính cho các Windows Controls.
• Bước 2: Viết lệnh
– Xác định các công việc cần thực hiện chọn các sự kiện
thích hợp trên các Windows Controls.
– Viết các phương thức đáp ứng các sự kiện trên.
Copyright © Wondershare Software
• Các Windows Controls :
– Control là lớp (class) các thành phần được thêm vào
Windows Forms để tương tác giữa người sử dụng
với Windows.
– Có rất nhiều loại control trong Windows Forms như:
Label, TextBox, ListBox, ComboBox, Button, …
– Các control sử dụng trên Windows Forms dùng
namespace System.Windows.Forms.
Copyright © Wondershare Software
• Các thuộc tính (Properties)
– Properties là những thông tin mà ta có thể thay đổi
nội dung, cách trình bày … của người thiết kế để ứng
dụng vào control.
– Mỗi lớp (class) có nhiều property khác nhau. Tuy
nhiên, vẫn có một số property giống nhau được xây
dựng từ lớp ban đầu.
Copyright © Wondershare Software
Copyright © Wondershare Software
Copyright © Wondershare Software
Copyright © Wondershare Software
Copyright © Wondershare Software
Copyright © Wondershare Software
Copyright © Wondershare Software
Copyright © Wondershare Software
• Các thuộc tính chung :
– Font=“Microsoft Sans Serif”;Size=“12”;Bold=True
• Form:
– Name=“FrmDangNhap”;Text=“Form Đăng Nhập”
• Label:
– Name=“Label1”; Text=“Tên Đăng Nhập”
– Name=“Label2”; Text=“Mật Khẩu”
• TextBox:
– Name=“txtUser”; Text=“”
– Name=“txtPass”; Text=“”
Copyright © Wondershare Software
• CheckBox:
– Name=“chkNho”; Text=“Ghi Nhớ”
• Button:
– Name=“btnDangNhap”; Text=“Đăng Nhập”
– Name=“btnXoa”; Text=“Xóa”
– Name=“btnDung”; Text=“Dừng”
Copyright © Wondershare Software
Copyright © Wondershare Software
• Nhắp đúp vào button btnDangNhap, thêm
đoạn code sau:
Copyright © Wondershare Software
Copyright © Wondershare Software
Copyright © Wondershare Software