Thông tin tài liệu:
Bài giảng "Lập trình Windows - Common Dialog" trình bày các nội dung: Giới thiệu Common Dialog, OpenFileDialog, SaveFileDialog, FontDialog, ColorDialog, MessageBox. Đây là một tài liệu hữu ích dành cho các bạn sinh viên ngành Công nghệ thông tin và những ai quan tâm dùng làm tài liệu học tập và nghiên cứu.
Nội dung trích xuất từ tài liệu:
Bài giảng Lập trình Windows - Common DialogCommonDialog 1NộiDung Giới thiệu Common Dialog OpenFileDialog SaveFileDialog FontDialog ColorDialog MessageBox 2CommonDialog Các dialog thường được sử dụng Được warp thành các lớp trong FCL/BCL OpenFileDialog SaveFileDialog FontDialog ColorDialog PrintDialog PrintPreviewDialog 3Color&FontDialogsCommonDialog Cách sử dụng 1. Kéo thả dialog vào form VS sẽ tạo thể hiện chứa trong lớp form 2. Khai báo đối tượng và tạo thể hiện của lớp CD VD: OpenFileDialog oFile = new OpenFileDialog(); CommonDialog 5NộiDung Giới thiệu Common Dialog OpenFileDialog SaveFileDialog FontDialog ColorDialog MessageBox 6OpenFileDialog Sử dụng để chọn file lưu trên đĩa Cách sử dụng từ ToolBox Drag&drop Codephát sinhtựđộngdlgColor.ShowDialog( ) xyz.Designer.csdlgFont.ShowDialog( )dlgPrint.ShowDialog( ) 7OpenFileDialog Code phát sinh của VS xyz.Designer.cs Tạothểhiện HiểnthịForm openFil eDialog 1.Show Dialog( ); 8OpenFileDialog Code tự viết – không dùng Toolbox 9OpenFileDialog Thuộc tính, phương thứcThuộc tínhFileName Lấy tên file được chọnFileNames Lấy tên tất cả các file được chọnFilter Xác định kiểu file cần mởInitialDirectory Thư mục khởi tạoMultiselect Cho phép chọn nhiều fileTitle Tiêu đề của dialogPhương thứcShowDialog Hiển thị dialogSự kiệnFileOk Xuất hiện khi user kích vào OK 10OpenFileDialog Ví dụ: Chọn tập tin privatevoidmởFileToolStripMenuItem_Click(objectsender, EventArgse) {//Gántậptinđangchọnnếutrướcđóđãchọn openFileDialog1.FileName=txtFile.Text; if(openFileDialog1.ShowDialog()==DialogResult.OK) { //GántậptinchọnvàođiềukhiểnTextBox txtFile.Text=openFileDialog1.FileName; } } 11OpenFileDialog Ví dụ: Đối tượng OpenFileDialog privatevoidmởFileToolStripMenuItem_Click(objectsender, EventArgse) { //KhaibáovàkhởitạođốitượngOpenFileDialog openFileDialogOD=newopenFileDialog(); //Gántậptinđangchọnnếutrướcđóđãchọn OD.FileName=txtFile.Text; if(OD.ShowDialog()==DialogResult.OK) { //GántậptinchọnvàođiềukhiểnTextBox txtFile.Text=OD.FileName; } } 12OpenFileDialog Ví dụ: Chọn nhiều tập tin privatevoidmởFileToolStripMenuItem_Click(objectsender, EventArgse) { //KhaibáovàkhởitạođốitượngOpenFileDialog OpenFileDialogOD=newOpenFileDialog(); //Chophépngườisửdụngchọnnhiềutậptin OD.Multiselect=true; //Gántậptinđangchọnnếutrướcđóđãchọn if(OD.ShowDialog()==DialogResult.OK) { //Duyệtquatừngtậptin foreach(stringnameinOD.FileName) { richTextBox1.AppendText(name+
); } } } 13NộiDung Giới thiệu Common Dialog OpenFileDialog SaveFileDialog FontDialog ColorDialog MessageBox 14SaveFileDialog Sử dụng để tạo file trên đĩa. Cách sử dụng Sử dụng SaveFileDialog component trên Toolbox Tương tự như OpenFileDialog! Tạo thể h ...