Vous êtes sur la page 1sur 2

TRUNG TÂM ĐÀO TẠO LẬP TRÌNH VIÊN QUỐC TẾ HUE-APTECH

Địa chỉ: 6 Lê Lợi, Huế Điện thoại: 3823077 Fax: 3823649 Email: hue-aptech@huesoft.com.vn

WINFORMS WITH C# - SESSION 2


1. Create a window application having two forms, as given in following question:
a. The first form having a clock and allows directing to another form, such as figure 1.1.

Figure 1.1 Mainform


In this form:
• Exit: to exit application
• ImageViewer: to load form ImageViewer
• Time: display the clock
Hints:
- Using Time control
- Using DateTime class
- Code to handler Tick event:
private void tmrTime_Tick(object sender, System.EventArgs e)
{
DateTime dt= DateTime.Now;
int h= dt.Hour;
int m= dt.Minute;
int s= dt.Second;
label1.Text = h.ToString()+ ":" + m.ToString() +":"+ s.ToString();
}

b. The second form contains a Textbox, four command buttons, a ListView, a picturebox
and another controls, such as Figure 1.2

Figure 1.2. ImageViewer


 Bài tập Winform with C# Page 1 of 2
# Trần Văn Long – Email: tvlong@huesoft.com.vn
TRUNG TÂM ĐÀO TẠO LẬP TRÌNH VIÊN QUỐC TẾ HUE-APTECH
Địa chỉ: 6 Lê Lợi, Huế Điện thoại: 3823077 Fax: 3823649 Email: hue-aptech@huesoft.com.vn

In this form:
• Textbox: allow entering path contain GIF images.
• OK: using when you change the path in the textbox, the first state of this button is
disabled. When the text had been change, it is enabled. And when you click in this
button images in Listview had been changed.
• Listview: display all images having in path which had been typed in textbox.
• PictureBox: display selected image in Listview.
• Textview, LargeView, SmallView button: used to change view state of listview.
• Close: to close this form.
Hints:
- Function to get all GIF images:
public static void loadForm(string path, ImageList imgl, ListView l){
DirectoryInfo thisfolder= new DirectoryInfo(@path);
object[] images=thisfolder.GetFiles("*.GIF");
int i=0;
imgl.Images.Clear();
foreach(object s in images)
{
string file= path +"\\" + s.ToString();
imgl.Images.Add(new System.Drawing.Bitmap(@file));
l.Items.Add(s.ToString(),i);
i++;
}
}
- Event handler SelectIndex change
lstImages: is a ListView control in this form
picImage: is a PictureBox control in this form
txtFolder: is a TextBox control in this form
private void lstImages_SelectedIndexChanged(object sender, System.EventArgs e)
{
foreach(ListViewItem o in lstImages.SelectedItems){
string file= txtFolder.Text +"\\" + o.Text;
Image img= new System.Drawing.Bitmap(@file);
picImage.Image= img;
lstImages.Select();
}

2. Create a window application such as exercise 1, but in the second form using TreeView
to replace Textbox and OK button. TreeView should allow selected folder which contains
GIF images.

 Bài tập Winform with C# Page 2 of 2


# Trần Văn Long – Email: tvlong@huesoft.com.vn

Vous aimerez peut-être aussi