Giáo trình C winform phần 2.1Giáo trình C winform phần 2.1Giáo trình C winform phần 2.1Giáo trình C winform phần 2.1Giáo trình C winform phần 2.1Giáo trình C winform phần 2.1Giáo trình C winform phần 2.1Giáo trình C winform phần 2.1Giáo trình C winform phần 2.1Giáo trình C winform phần 2.1Giáo trình C winform phần 2.1Giáo trình C winform phần 2.1Giáo trình C winform phần 2.1Giáo trình C winform phần 2.1Giáo trình C winform phần 2.1Giáo trình C winform phần 2.1Giáo trình C winform phần 2.1Giáo trình C winform phần 2.1Giáo trình C winform phần 2.1Giáo trình C winform phần 2.1Giáo trình C winform phần 2.1v
Trang 1L p trình trên môi tr ậ ườ ng Windows
Windows control - Ph n 1 ầ
Tr n Duy Hoàng ầ
tdhoang@hcmus.edu.vn
Trang 3Form
Trang 8private void DemoForm_Load(object sender, EventArgs e){
this.Text = "Demo";
this.Size = new Size(500, 500);
this.BackgroundImage = new Bitmap("background.jpg"); this.Opacity = 0.75;
Trang 9Form
Trang 10● Ch a danh sách các control con c a nó ứ ủ
● Thêm xóa đ ng các control vào form ộ
Button btn = new Button;
btn.Text = “Hello”;
btn.Size = new Size (50, 50);
btn.Location = new Point (10,10);
this.Controls.Add(btn);
Trang 11this.ClientSize = new Size(500, 500);
Button[,] arrButton = new Button[10, 10];
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
arrButton[i,j] = new Button();
arrButton[i,j].Size = new Size(50, 50);
arrButton[i,j].Location = new Point(j * 50, i * 50); this.Controls.Add(arrButton[i,j]);
}
}
Trang 12Form
Trang 16● KeyDown(), KeyUp()
➢ if (e.KeyCode == Keys.F5) { ThemNhanVien();
e.Handled = true;}
➢ if (e.KeyCode == Keys.N && e.Control == true) { ThemNhanVien();
e.Handled = true;
Trang 20● Validating() / Validated()
● TextChange
Trang 24● SelectedIndexChanged
● SelectedValueChanged
Trang 25}
Trang 26Dialog thông d ng ụ
OpenFileDialog dialog = new OpenFileDialog();
dialog.InitialDirectory = Application.ExecutablePath; dialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"; dialog.FilterIndex = 2;
dialog.RestoreDirectory = true;
if (dialog.ShowDialog() == DialogResult.OK)
{
Trang 27Dialog thông d ng ụ
SaveFileDialog dialog = new SaveFileDialog();
dialog.InitialDirectory = Application.ExecutablePath; dialog.Filter = "txt files (*.txt)|*.txt";
Trang 28Dialog thông d ng ụ
FolderBrowserDialog dialog = new FolderBrowserDialog(); dialog.RootFolder = Environment.SpecialFolder.Desktop; dialog.ShowNewFolderButton = true;
if (dialog.ShowDialog() == DialogResult.OK)
{
MessageBox.Show(dialog.SelectedPath);
}
Trang 29Dialog thông d ng ụ
Trang 30
Dialog thông d ng ụ
Trang 31
Tr n Duy Hoàng - tdhoang@fit.hcmus.edu.vn ầ
Th o lu n ả ậ