YOMEDIA
ADSENSE
Chương 3: Lập trình với Windows Forms
201
lượt xem 61
download
lượt xem 61
download
Download
Vui lòng tải xuống để xem tài liệu đầy đủ
Windows Forms is part of the .NET framework...
AMBIENT/
Chủ đề:
Bình luận(0) Đăng nhập để gửi bình luận!
Nội dung Text: Chương 3: Lập trình với Windows Forms
- Chapter 3 Ch Programming with Windows Forms Programming Department of Software Engineering Faculty of Information Technology Natural Sciences University
- Agenda Agenda Introduction Windows Forms How to handle events in Windows Forms Adding controls to forms (design-time) Dynamically adding controls to Forms Dynamically (runtime) (runtime) Using Complex Controls Using Creating GUI Components Creating Working with Menu Creating MDI applications with Windows Creating Forms Forms Deploying Windows Forms Applications
- What is Windows Forms (a.k.a. WinForms)? WinForms)? Windows Forms is part of the .NET framework core classes in System.Windows.Forms core namespace namespace design-time support in various namespaces Windows Forms provides classes for building Windows UIs UIs e.g. custom forms, common controls, standard e.g. dialogs dialogs Visual Studio .NET provides tools for using Visual Windows Forms Windows templates for common starting places, and a templates visual designer visual
- Windows Forms Application Structure Windows A Windows Forms application has three pieces the application itself forms in the application controls on the form Label MyForm Application “Hell…” label1 Button mainForm button1 “OK”
- System.Windows.Forms.Application System.Windows.Forms.Application The Application class represents the application The itself itself no instances (all properties and methods are static) processes UI events delivered by Windows Run, DoEvents DoEvents provides access to application environment ExecutablePath, StartupPath StartupPath CommonAppDataPath, UserAppDataPath UserAppDataPath CommonAppDataRegistry, UserAppDataRegistry UserAppDataRegistry class MyApp { public static void Main() { MyForm form = new MyForm(); System.Windows.Forms.Application.Run(form); } }
- System.Windows.Forms.Form System.Windows.Forms.Form Instances of the Form class represent Instances windows windows provide window-style services, e.g. properties: Text, Size, Location, Controls properties: Text, methods: Show, ShowDialog, Close methods: Show, events: Load, Click, Closing events: Load, custom forms typically derive from base Form custom Form class class class MyForm : Form { public MyForm() { this.Text = "This is my form!"; this.Location = new Point(10, 10); this.Size = new Size(100, 100); } }
- Form appearance Form Various properties influence a form’s appearance Property Type Purpose Text string Text to display (if applicable) Location Point Upper/left coordinate of form Size Point Width/height of form Font Font Get/set displayed text font ForeColor Color Get/set foreground color Get/set degree of opacity (as Get/set Opacity double a %) %) (many more…) … … Often, changing a property results in event notification Move (Location), Resize (Size), FontChanged (Font) ), Resize ), FontChanged
- Controls Controls Controls are visual components System.Windows.Forms.Control is base class for UI System.Windows.Forms.Control elements elements e.g. Form, Button, Label, TextBox, ListBox, etc. e.g. Form, contained and arranged by parent (usually a Form) held in parent’s Controls collection held Controls public class MyForm : Form { private Button button1; public MyForm() { button1 = new Button(); button1.Text = "Click Me!"; button1.Location = new Point(10, 10); this.Controls.Add(button1); } }
- Control interaction (part 1) Control Public events are used by control Public “consumers” “consumers” containing form/control registers for events of containing interest interest public class MyForm : Form { private Button button1; public MyForm() { button1 = new Button(); ... button1.Click += new EventHandler(button1_Click); } void button1_Click( object sender, EventArgs e ) { // Handle event as needed... } }
- Control interaction (part 2) Control Derived controls/forms have two approaches may register for base class events may override corresponding virtual functions (if provided) Decision driven by functionality desired, not Decision performance performance event versus override approach equivalent in many cases overriding provides control over when/if events are fired public EveryOtherClickButton : Button { private int clickNum = 0; protected override void OnClick( EventArgs e ) { clickNum++; if( (clickNum % 2) == 0 ) base.OnClick(e); // Button.OnClick fires Click event } }
- Complex Controls Complex Docking Controls Anchor a control to Anchor one edge of its container one Make a control fill Make the available space in its container the Splitter Windows Allow docked controls to be resized at run time Allow by the user by Panels Control Group controls together or subdivide a form into Group functional areas functional TreeView and ListView controls ListView Controls for Navigating Data
- The Explorer Interface The
- User Controls User A User Control has all the basic functionality User for a graphical control that will be used on a Windows Form. Inherits from System.Windows.Forms.UserControl System.Windows.Forms.UserControl Inherited Properties can override these properties. Inherited Events can override these inherited events if you need can to, but it is best if you override only the inherited On method instead of directly On overriding the base event, so that future controls may benefit from the standards. may
- Menu Menu MainMenu component displays a menu at run time. All submenus of the main menu and individual All items are MenuItem objects. MenuItem ContextMenu component ContextMenu is used to provide users with an easily accessible Pop-up menus that appear when you accessible right-click a form or control.
- MDI applications MDI MDI – Multiple Document Interface Form Properties IsMDIContainer MDIParent ActiveMDIChild MenuItem Properties MergeType & MergeOrder MDIList Arrange MDIChilds MdiLayout.Cascade, MdiLayout.TileHorizontal, or MdiLayout.TileHorizontal or MdiLayout.TileVertical MdiLayout.TileVertical
- Deploying Windows Forms Applications Applications Microsoft Windows Microsoft Installer Service Installer keeps track of every keeps application that's installed on a computer installed allows to uninstall, allows repair, or reinstall a package based on the state of the machine state allows to roll back allows installations. Deployment Projects Templates Templates
- Deploying Windows Forms Applications (cont) Applications Creating a Windows Installer Package Setup project properties File Installation Management Registry Settings Management File Types Management User Interface Management Custom Actions Management Launch Condition Management
- References References www.msdn.microsoft.com MS Press Microsoft Visual C Sharp Dot NET MS Step By Step Version.2003 - l-mcs301-2003- Step 11-25 Sams Teach Yourself Sams Visual.Studio.Dot.Net.2003.In.21Days - l- Visual.Studio.Dot.Net.2003.In.21Days stdn02-2003-7-11.rar FTP: 172.29.22.45 FTP: 172.29.22.45 Username: sv Password: sv Password: sv Directory: dotNET
ADSENSE
CÓ THỂ BẠN MUỐN DOWNLOAD
Thêm tài liệu vào bộ sưu tập có sẵn:
Báo xấu
LAVA
AANETWORK
TRỢ GIÚP
HỖ TRỢ KHÁCH HÀNG
Chịu trách nhiệm nội dung:
Nguyễn Công Hà - Giám đốc Công ty TNHH TÀI LIỆU TRỰC TUYẾN VI NA
LIÊN HỆ
Địa chỉ: P402, 54A Nơ Trang Long, Phường 14, Q.Bình Thạnh, TP.HCM
Hotline: 093 303 0098
Email: support@tailieu.vn