Danh mục

Chapter 3: Programming with Windows Forms

Số trang: 18      Loại file: ppt      Dung lượng: 1.24 MB      Lượt xem: 10      Lượt tải: 0    
Jamona

Hỗ trợ phí lưu trữ khi tải xuống: 17,000 VND Tải xuống file đầy đủ (18 trang) 0
Xem trước 2 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

Agenda:Introduction Windows Forms,How to handle events in Windows Forms,Adding controls to forms (design-time),Dynamically adding controls to Forms(runtime),Using Complex Controls,Creating GUI Components,Working with Menu,Creating MDI applications with WindowsForms,Deploying Windows Forms Applications.
Nội dung trích xuất từ tài liệu:
Chapter 3: Programming with Windows Forms Chapter 3Programming with Windows Forms Department of Software Engineering Faculty of Information Technology Natural Sciences University AgendaIntroduction Windows FormsHow to handle events in Windows FormsAdding controls to forms (design-time)Dynamically adding controls to Forms(runtime)Using Complex ControlsCreating GUI ComponentsWorking with MenuCreating MDI applications with WindowsFormsDeploying Windows Forms Applications What is Windows Forms (a.k.a. WinForms)?Windows Forms is part of the .NET framework core classes in System.Windows.Forms namespace design-time support in various namespacesWindows Forms provides classes for buildingUIs e.g. custom forms, common controls, standard dialogsVisual Studio .NET provides tools for usingWindows Forms templates for common starting places, and a visual designerWindows Forms Application Structure A Windows Forms application has three pieces the application itself forms in the application controls on the form Application MyForm Label label1 “Hell…” mainForm Button button1 “OK”System.Windows.Forms.Application The Application class represents the application itself no instances (all properties and methods are static) processes UI events delivered by Windows Run, DoEvents provides access to application environment ExecutablePath, StartupPath CommonAppDataPath, UserAppDataPath CommonAppDataRegistry, UserAppDataRegistry class MyApp { public static void Main() { MyForm form = new MyForm(); System.Windows.Forms.Application.Run(form); } } System.Windows.Forms.FormInstances of the Form class representwindows provide window-style services, e.g. properties: Text, Size, Location, Controls methods: Show, ShowDialog, Close events: Load, Click, Closing custom forms typically derive from base Form 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 Various properties influence a form’s appearanceProperty Type PurposeText string Text to display (if applicable)Location Point Upper/left coordinate of formSize Point Width/height of formFont Font Get/set displayed text fontForeColor Color Get/set foreground colorOpacity double Get/set degree of opacity (as a %)(many more…) … … Often, changing a property results in event notification Move (Location), Resize (Size), FontChanged (Font) ControlsControls are visual components System.Windows.Forms.Control is base class for UI elements e.g. Form, Button, Label, TextBox, ListBox, etc. contained and arranged by parent (usually a Form) held in parent’s Controls collection 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)Public events are used by control“consumers” containing form/control registers for events of 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)Derived controls/forms have two approaches may register for base class events may override corresponding virtual functions (if provided)Decision driven by functionality desired, notperformance event versus override approach equivalent in many cases overriding provides control over when/if events are firedpublic 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 ControlsDocking Controls Anchor a control toone edge of its container Make a control fillthe available space in its containerSplitter Windows Allow docked controls to be resized at run time by the userPanels Control Group controls together or subdivide a form into ...

Tài liệu được xem nhiều: