Giáo án - Bài giảng: COMMON DIALOG & CUSTOM CONTROL, SỬ DỤNG C#

46 768 0
Giáo án - Bài giảng: COMMON DIALOG & CUSTOM CONTROL, SỬ DỤNG C#

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Common Dialog & User Control Nguyễn Văn Phong Nội Dung ° Giới thiệu Common Dialog a OpenFileDialog a SaveFileDialog a FontDialog a ColorDialog a MessageBox a User Control Nguyễn Văn Phong - 2010 Common Dialog Các dialog thường được sử dụng ° Được warp thành các lớp trong FCL/BCL OpenFileDialog ColorDialog Common Dialog SaveFileDialog FontDialog PrintDìalog Nguyễn Văn Phong - 2010 Common Dialog Cách sử dụng a 1. Kéo thả dialog vào form ■ vs sẽ tạo thể hiện chứa trong lớp form a 2. Khai báo đối tượng và tạo thể hiện của lớp CD ■ VD: OpenFileDialog oFile = new OpenFileDialogO; Oft © % s o © u z Printing ^ Pointer t3 i PageSetupDialog PfintOialog PrintDocument Í PrintPreviewControl PrintPreviewDialog Ẽ Dialogs Pointer ColorDialog J FolderBrowserDialog a FontDialog Jf] OpenFileDialog y j SaveFileDialog / B Form2 Nguyễn Văn Phong - 2010 Nội Dung a Giới thiệu Common Dialog ü OpenFileDialog a SaveFileDialog a FontDialog a ColorDialog a MessageBox a User Control Nguyễn Văn Phong - 2010 OpenFileDialog ■ sử dụng để chọn file lưu trên đĩa ■ Cách sử dụng từ ToolBox p— ^ Ẽ8 Fo rm l OS® - Dialogs ^ Pointei Drag & drop •TỊ ColarDialog J i FolderBrowserDialog ^ 3 FontDialog r ¿1 OpenRleDialog f ■ ir l SaverleOiolog ■ a ■ ■ ■ a ■ ■ a ỹ l openFileDialogl Windows Form Designer generated codq Code phát sinh tự động xyz.Designer.cs private System.Windows.Forms.OpenFileDialog openFileDialogl; Nguyễn Văn Phong - 2010 H OpenFileDialog Code phát sinh của vs xyz.Designer.cs private void InitializeComponent() ( this.openFileDialogl = new System.Windows.Forms.OpenFileDialog(), this. SuspendLayout(); | _ « i v // openFileDialogl l a o t h e l u e n // this.openFileDialogl.FileName = "openFileDialogl"; // // Forml // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F) ; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(262, 202); this.Name = "Forml"; this.Text = "Forml"; this.Load += new System.EventHand this.ResumeLayout(false); #endregion Hien thi Form WogQ; private System.Windows.Forms.OpenFileDialog openFileDialogl; Nguyễn Văn Phong - 2010 ■ Code tự viết - không dùng Toolbox OpenFileDialog // tạo thế hiện OpenFileDialog OpenFileDialog OFileDlg = new OpenFileDialoq(); // thiêt lập các option // cho phép chọn nhiêu file OFileDlg.Multiselect = true; // lọc chỉ mở những file c# source code OFileDlg.F ilte r = "c# source code I * .cs DialogResult result; // hiển thị và lấy giá trị trả về result = OFileDlg.ShowDialog(); // xử lý tiêp theo Nguyễn Văn Phong - 2010 OpenFileDialog Thuộc tính, phương thức Thuôc tính • FileName Lấy tên file được chọn FileNames Lấy tên tất cả các file được chọn Filter Xác đinh kiểu file cần mở ■ InitialDirectory Thư muc khởi tao ■ ■ Multiselect Cho phép chọn nhiêu file Title Tiêu để của dialog Phương thức ShowDialog Hiển thị dialog kiên • m __S ' — N g i y l 11 w i n ỉ ¡ ' o n g - 2 0 1 0 xuat men Khi user Kicn vao UK Nội Dung a Giới thiệu Common Dialog a OpenFileDialog ° SaveFileDialog a FontDialog a ColorDialog a MessageBox a User Control Nguyễn Văn Phong - 2010 [...]... Save Ole Dialog Nhp on text t Dialogs Drag & drop Pointer ColorDialog J 1 FolderBrowserDialog^ A FontDialog y OpenFileDialog j r l SaveFileDialog M j r ] saveFileDialog 1 Nguyờn Vn Phong - 2010 ylooenFileDialoal SaveFileDialog Vit phn x lý button M file 43 // chc nng m file txt v hin th ni dung 44 openFileDialogl.Filter = "Text File (* txt) 1* txt"; 45 ) 4 6 if (openFileDialogl.ShowDiaJLog ( == DialogResult.OK)... Dialog Nhp on text Dialogs - Pointer Drag & drop 71 ColorDialog Multiline=true JF1 FolderBrowserDialog FontDialog n OpenFileDialog J ; y | SaveFileDialog LUu file l saveFileDialogl Nguyn Vn Phong - 2010 SaveFileDialog Vit phn x lý cho button Lu file 21 22 System.1 b 23 24 25 26 27 28 29 3Q 32 33 34 35 36 37 38 Nguyờn Vn Phong - 2010 // phn x lý ch button lu // lu dng text saveFileDialogl.Filter = "Text... FontDialog a ColorDialog a MessageBox a User Control Nguyn Vn Phong - 2010 ColorDialog Hin th chc nng chn mu s dng theo 2 cỏch a Kộo ColorDialog t Toolbox th vo form a Vit code to ụi tng ColorDialog s dng giỏ tr mu cú kiu Color a MuARGB Alpha Red Green Blue Nguyn Vn Phong - 2010 ColorDialog Demo chn mu: chn mu nn cho form r Demo ColorDialog - Dialogs Drag & drop / Color 1^ Pointer 1 ColorDialog... th/ khụng button Apply Phng thc ShovvDialog Hin th dialog ra mn hỡnh S kiờn Apply Kớch hot khi user chn apply * FontDialog Demo: gi FontDialog thit lp font cho control To Form cú dng sau Label test font ^ Pointer ta ColcrDialog \ FolderBrowserDialog |3ô*1 FontDialog y | OpenFileDialog ^ 1 SaveFileDialog chon font J3 fontDialogl Nguyờn Vn Phong - 2010 FontDialog Phn x lý cho button Font 21 22...SaveFileDialog s dng to file trờn a Cỏch s dng a S dng SaveFileDialog component trờn Toolbox Tng t nh OpenFileDialog! a To th hin ca lỏp SaveFileDialog // to th hin Save File Dialog SaveFileDialog saveDlg = new SaveFileDialog0; // save di dng txt saveDlg Filter = "Text File I* tx-t"; // hin th dialog v ly giỏ tr tr v ca dialg DialogResult result = saveDlg.ShowDialog(); // nu user... Studio Express & Irk link tai lieu minipad 1 pass aptech s ' Save File Dialog đ1 đ Nhp on text * Nguyn H Giang n Hutech Email: nguyenha.giang@jiahoo.com H_JTAl xu6ng ii 5Visual Studio 20(35 My Compute 3 My Network Fie QameFies of Jype- giansLprofile ĂText FỹefMxt) Mb file Nguyn Vn Phong - 2010 LJu file Ni Dung a Gii thiu Common Dialog a OpenFileDialog a SaveFileDialog a FontDialog a ColorDialog a MessageBox... ColorDialog J 1 =olderBrowserDialog =ontDialog j r l OpenFileDialog s \ 5aveFileDialog * colorDialogl 1 Nguyờn Vn Phong - 2010 ColorDỡalog Phn x lý cho button Color if (colorDialogl.ShowDialog( == DialogResult.OK) ) { // lõy bờ mt v ca form Graphics g = this.CreateGraphics( ; ) // hỡnh ch nht ca form Rectangle rect = new Rectangle(0,0,width,Height); // to brush gradient: cú mu c chn -> white IiinearGradieivtBrush... IiinearGradieivtBrush brush = new LinearGradientBrush(rect, colorDialogl.Color, Color.white, LinearGradientMode.Horizontal) ; // tụ nen ca form g FillRect-angle (brush, rect) ; Color Nguyn Vn Phong - 2010 Ni Dung a Gii thiu Common Dialog a a a a OpenFileDialog SaveFileDialog FontDialog ColorDialog a MessageBox a User Control Nguyn Vn Phong - 2010 MessageBox Hin th hp thoi cha thụng tin ch dn n user ... 29 fontDialogl.ShowApply = true; 30 31 // ng ký s kin khi button Apply dc nhn foiitDialogl Apply += new EventHandler (ChangeFont); 47 48 52 Nguyn Vn Phong - 2010 void ChangeFont(object sender, EventArgs e) { // thit lp font mi cho label labell.Font = fontDialogl.Font; // thit lp mu mi cho label labell.ForeColor = fontDialogl.Color; > Ni Dung a Gii thiu Common Dialog a OpenFileDialog a SaveFileDialog... (result == DialogResult.OK) { } Nguyn Vn Phong - 2010 // TO DO SaveFileDialog Demo: nhp van bn vo textbox, sau ú lu xung file *.txt a To ng dng dng Windows Form cú cỏc control 1 label: caption ca textbox 1 textbox: cha ni dung text do user nhp 1 button: gi SaveFileDialog v lu file 1 SaveFileDialog: khai bỏo dialog SaveFile Nguyn Vn Phong - 2010 SaveFileDialog Thit kờ form a Save File Dialog Nhp . Phong - 2010 Common Dialog Các dialog thường được sử dụng ° Được warp thành các lớp trong FCL/BCL OpenFileDialog ColorDialog Common Dialog SaveFileDialog FontDialog PrintDìalog Nguyễn Văn Phong -. OpenFileDialog ° SaveFileDialog a FontDialog a ColorDialog a MessageBox a User Control Nguyễn Văn Phong - 2010 SaveFileDialog ■ sử dụng để tạo file trên đĩa. ■ Cách sử dụng a Sử dụng SaveFileDialog. Phong - 2010 Nội Dung a Giới thiệu Common Dialog ü OpenFileDialog a SaveFileDialog a FontDialog a ColorDialog a MessageBox a User Control Nguyễn Văn Phong - 2010 OpenFileDialog ■ sử dụng

Ngày đăng: 16/04/2014, 17:48

Từ khóa liên quan

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan