Yêu cầu: Viết chương trình cho đếm ngược từ 10, hết thời gian thì hiện ra một hình ảnh nào đó.. Yêu cầu: Viết chương trình cho hiển thị hình ảnh tự động theo thứ tự sau một khoảng thời
Trang 1Bài 20:
Mục đích:
+ Sử dụng Timer
Yêu cầu:
Viết chương trình cho đếm ngược từ 10, hết thời gian thì hiện ra một hình ảnh nào đó
Bài 21:
Mục đích:
+ Sử dụng Timer
Yêu cầu:
Viết chương trình cho hiển thị hình ảnh tự động theo thứ tự sau một khoảng thời gian nào đó
Bài 22:
Mục đích:
+ Sử dụng TreeView
Yêu cầu:
+ Thiết kế giao diện như sau:
+ Thực hiện các yêu cầu sau:
Thiết lập HideSelection = False
Nút Cập Nhật: Thêm 1 SV vào lớp đang chọn trên TreeView với nội dung các nút như hình
Trang 2Trước khi thêm phải kiểm tra thông tin nhập gồm: các ô nhập không được để trống, không được trùng mã SV Ngoài ra còn phải kiểm tra nút chọn trên TreeView có phải là nút lớp không (chỉ được thêm vào nút lớp)
Nút Xóa: cho phép xóa nút đang chọn trong TreeView, phải xác nhận lại trước khi xoá và chỉ được xoá khi chọn nút chứa mã sv
Khi click chọn nút mã sv hoặc địa chỉ thì hiện thông tin sv đó qua các textbox
Quy định Form hiển thị giữa màn hình
Quy định việc di chuyển tab hợp lý
Thiết lập thuộc tính Dock hợp lý cho TreeView
Thiết lập MinimumSize cho form
Bài 23:
Mục đích:
+ Tạo user-control với Label, Textbox và viết ứng dụng kiểm thử
Yêu cầu:
+ Thực hiện theo hướng dẫn trong giáo trình từ trang 523 đến 530
+ Bài tập 1 trang 531
Bài 24:
Mục đích:
+ Tạo user-control với Timer và viết ứng dụng kiểm thử
Yêu cầu:
Create a user control, which will display a countdown timer The timer can accept a value from the user (at design time when added on a new form) indicating the number of seconds to start counting from
Solutions:
1 Create a Windows Control Library named TimerControl
2 Rename UserControl1.cs to TimerControl.cs Design the interface of the user
control as follows (with the label named lblTimeCounter and the timer named
tmrCountdown):
Trang 3Figure 7.1: User Interface
3 Declare a private variable named _seconds as follows:
private int _seconds;
4 Create a property called Seconds as follows:
public int Seconds
{
get {
return _seconds;
} set {
_seconds = value;
} }
5 Create two methods Start and Stop, which will start and stop the countdown respectively Add the following code to the methods Start() and Stop()
public void Start()
{
tmrCountdown.Enabled = true;
tmrCountdown.Interval = 1000;
lblTimeCounter.Text = _seconds.ToString();
tmrCountdown.Start();
}
public void Stop()
{
tmrCountdown.Stop();
tmrCountdown.Enabled =false;
}
6 Add the following code to the Tick event of the timer:
private void tmrCountdown_Tick(object sender, System.EventArgs e) {
Trang 4Console.Write(_seconds);
_seconds -= 1;
if (_seconds <=0)
{
tmrCountdown.Stop();
tmrCountdown.Enabled = false;
}
lblTimeCounter.Text = _seconds.ToString();
}
7 Save and Build the project This will create the dll file
8 Create a new Windows project of type Windows Application called TimerTest Add the user control created previously into this form Add two Button controls to this form Set the
properties of the form, the buttons and custom control appropriately
9 Add relevant code as shown below to the Click events of the buttons Start and Stop
private void btnStart_Click(object sender, System.EventArgs e)
{
tmrControl.Start();
}
private void btnStop_Click(object sender, System.EventArgs e)
{
tmrControl.Stop();
}
10 Save and Build the project Execute it and observe the output
11 Sample output is shown in Figure 7.2
Figure 7.2: Sample Output (From Aptech Lab)