Bài giảng Lập trình nâng cao: Bài 7 - Lý Anh Tuấn

33 41 0
Bài giảng Lập trình nâng cao: Bài 7 - Lý Anh Tuấn

Đ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

Bài giảng Lập trình nâng cao - Bài 7: Ngôn ngữ lập trình nâng cao cung cấp cho người học các kiến thức: Lập trình Winform với C thăng, tại sao sử dụng Windows Forms, cấu trúc Windows Forms, sử dụng Windows Forms, sử dụng các Control,... Mời các bạn cùng tham khảo.

Object-Oriented Programming Using C# NGƠN NGỮ LẬP TRÌNH NÂNG CAO Ver 1.0 Slide of 21 Object-Oriented Programming Using C# Lập trình Winform với C# Giới thiệu chung Sử dụng IDE (Integrated Development Environment) VS để phát triển nhanh ứng dụng Sử dụng thư viện Windows Forms để phát triển ứng dụng desktop client server chạy môi trường Windows Thiết kế giao diện sử dụng IDE viết code C# Các tiêu chuẩn ứng dụng dạng Windows Forms Tìm hiểu control thuộc tính thơng dụng control Ver 1.0 Slide of 21 Object-Oriented Programming Using C# Lập trình Winform với C# Nội dung Tại sử dụng Windows Forms Cấu trúc Windows Forms Sử dụng Windows Forms Sử dụng Control Thừa kế Windows Forms Ver 1.0 Slide of 21 Object-Oriented Programming Using C# Tại sử dụng Windows Forms Có tập hợp cotrol phong phú Nhiều kiểu giao diện Hỗ trợ cải tiến việc in ấn Hỗ trợ cải tiến đồ họa – GDI+ Hỗ trợ khả truy cập qua thuộc tính control Hỗ trợ thừa kế Các đối tượng cải tiến Thuận lợi cho thiết kế forms Ver 1.0 Slide of 21 Object-Oriented Programming Using C# Cấu trúc Windows Forms Phân cấp lớp Windows Forms Sử dụng lớp Windows.Forms.Appication Nghiên cứu Code Behind Windows Forms Ver 1.0 Slide of 21 Object-Oriented Programming Using C# Phân cấp lớp Windows Forms Ver 1.0 Slide of 21 Object-Oriented Programming Using C# Sử dụng lớp Windows.Forms.Application Bắt đầu kết thúc ứng dụng static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } Thiết lập thông tin truy vấn thông tin ứng dụng string strAppPath = Application.StartupPath; ‘lấy đường dẫn chứa nơi cài file chạy Ver 1.0 Slide of 21 Object-Oriented Programming Using C# Nghiên cứu Code Behind Windows Forms Imports • Truy cập chức namespace tham chiếu assemblies using System.Windows.Forms Class • • • • Ver 1.0 Thừa kế từ System.Windows.Forms.Form Contructor – public Form1() Initializer – void InitializeComponent() Detructor – void Dispose() Slide of 21 Object-Oriented Programming Using C# Sử dụng Windows Forms Sử dụng Form Properties Sử dụng Form Methods Sử dụng Form Events Điều khiển kiện Tạo Form MDI Sử dụng dạng hộp thoại chuẩn Ver 1.0 Slide of 21 Object-Oriented Programming Using C# Sử dụng Form Properties Kích Form Control có hộp thoại Form Properties tương ứng Ver 1.0 Slide 10 of 21 Object-Oriented Programming Using C# Các thuộc tính kiện thông dụng Ver 1.0 Slide 19 of 21 Object-Oriented Programming Using C# Các thuộc tính kiện thơng dụng Ver 1.0 Slide 20 of 21 Object-Oriented Programming Using C# Các thuộc tính kiện thơng dụng Ver 1.0 Slide 21 of 21 Object-Oriented Programming Using C# Các control CheckedListBox LinkLabel Spliter ToolTip NotifyIcon Ver 1.0 Slide 22 of 21 Object-Oriented Programming Using C# Sử dụng Properties Control Đặt vị trí Control • Anchor • Location Thuộc tính Text Button1.Text = "Click Me" Ver 1.0 Slide 23 of 21 Object-Oriented Programming Using C# Sử dụng Methods Control BringToFront SendToBack Button1.BringToFront( ) Button2.SendToBack( ) Focus TextBox1.Focus( ) TextBox1.SelectAll( ) Ver 1.0 Slide 24 of 21 Object-Oriented Programming Using C# Tạo Menus Các lớp Menu Tạo Menu lúc thiết kế • Sử dụng Menu Designer Tạo Menu lúc chạy private System.Windows.Forms.MenuStrip menuStrip1; private System.Windows.Forms.ToolStripMenuItem mnuArrange; private System.Windows.Forms.ToolStripMenuItem mnuArrangeCasscade; this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {this.mnuArrange}); this.mnuArrange.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.mnuArrangeCasscade}); this.Controls.Add(this.menuStrip1); this.MainMenuStrip = this.menuStrip1; Ver 1.0 Slide 25 of 21 Object-Oriented Programming Using C# Cung cấp Help cho người sử dụng Control ErrorProvider • Icon lỗi xuất control kế tiếp, message xuất giống ToolTip chuột di chuyển qua Icon • Được sử dụng kiểm tra liệu đầu vào Control HelpProvider • Gắn file trợ giúp dạng *.chm, *.hlp, *.html • Control cung cấp thơng tin trợ giúp qua thuộc tính HelpString HelpTopic Ver 1.0 Slide 26 of 21 Object-Oriented Programming Using C# Thực thi chức Kéo – Thả Xử lý Dùng kiện MouseDown phương thức DoDragDrop kiện control kéo Tiếp tục dùng kiện DragOver control thả, thiết lập thuộc tính Effect tham số DragEventsArg kiện Sự kiện cuối DragDrop thực thả liệu Dùng phương thức Data.GetData kết hợp tham số DataFormats để lấy liệu kéo tới Ver 1.0 Slide 27 of 21 Object-Oriented Programming Using C# Thừa kế Windows Forms Tại thừa kế từ Form Tạo Form sở (Form Base) Tạo Form thừa kế Thay đổi Form Base Ver 1.0 Slide 28 of 21 Object-Oriented Programming Using C# Tại thừa kế từ Form Một Form class, dùng thừa kế Các ứng dụng có giao diện hoạt động theo chuẩn Các thay đổi form sở tác động tới form thừa kế Các ví dụ: Các form Wizard Các form Logon Ver 1.0 Slide 29 of 21 Object-Oriented Programming Using C# Tạo Form sở (Form Base) Lên kế hoạch Form Base cách cẩn thận Tạo Form Base form thơng thường Thiết lập thuộc tính truy cập cho control Private – Control truy cập form Base Protected – control truy cập form kế thừa Public – Control truy câp module Thêm từ khóa Overridable tới Method cách thích hợp Build Solution cho Form Base Ver 1.0 Slide 30 of 21 Object-Oriented Programming Using C# Tạo form thừa kế Đảm bảo form base hoàn thành Tham chiếu tới Assembly Tạo form thừa kế Thay đổi thuộc tính cần thiết Viết chồng Method Event có yêu cầu Ver 1.0 Slide 31 of 21 Object-Oriented Programming Using C# Thay đổi Form Base Thay đổi Form Base Các thay đổi tác động tới form kế thừa Rebuilt Kiểm tra form kế thừa Kiểm tra thay đổi trước rebuilt lại ứng dụng Kiểm tra lại sau rebuilt lại ứng dụng Ver 1.0 Slide 32 of 21 Object-Oriented Programming Using C# Bài tập Các lợi ích Windows Forms? Lớp ContainerControl lớp sở cho control khác hay sai? Viết code để truy cập tới đường dẫn file chạy ứng dụng Viết code để gọi btnOK người sử dụng ấn phím Enter Liệt kê control cung cấp trợ giúp cho người sử dụng Viết code để tạo menu Help với menu About lúc chạy chương trình Ver 1.0 Slide 33 of 21 ...Object-Oriented Programming Using C# Lập trình Winform với C# Giới thiệu chung Sử dụng IDE (Integrated Development Environment) VS để phát triển nhanh ứng dụng Sử dụng thư... Forms Tìm hiểu control thuộc tính thơng dụng control Ver 1.0 Slide of 21 Object-Oriented Programming Using C# Lập trình Winform với C# Nội dung Tại sử dụng Windows Forms Cấu trúc Windows Forms... Object-Oriented Programming Using C# Các thuộc tính kiện thơng dụng Ver 1.0 Slide 19 of 21 Object-Oriented Programming Using C# Các thuộc tính kiện thông dụng Ver 1.0 Slide 20 of 21 Object-Oriented

Ngày đăng: 15/05/2020, 22:56

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

Tài liệu liên quan