YOMEDIA
			  
  ADSENSE
Windows Forms
				
					64
					
lượt xem 5
download
			lượt xem 5
download
  Download
			
		    Vui lòng tải xuống để xem tài liệu đầy đủ
		Windows Forms Overview about describe the structure of a Windows Forms application (application entry point, forms, components and controls); Introduce deployment over networks. It provides about Visual Studio, Application Structure, Form border; Form properties.
AMBIENT/
	
	
	Chủ đề:
	Bình luận(0) Đăng nhập để gửi bình luận!
					
						Nội dung Text: Windows Forms					
				
			- Windows Forms
 - Overview • Describe the structure of a Windows Forms application – application entry point – forms – components and controls • Introduce deployment over networks 2
 - Windows Forms • Windows Forms are classes for building UIs – forms, controls, dialogs, etc. – part of the .NET Framework Library – core classes in System.Windows.Forms namespace • Possible uses include: – stand-alone Windows applications – web services front-ends – intranet “smart clients” 3
 - Visual Studio • Visual Studio .NET provides development environment – starter templates, drag-and-drop editing, property grid, etc. 4
 - Application Structure • Windows Forms application has three main pieces – the application itself – forms in the application – controls and components on the forms Label Application myForm "Hello, World!" mainForm label1 button1 Button "OK" 5
 - Application • Application class represents the application itself – Run method processes UI events delivered by Windows – provides access to application environment ExecutablePath, CommonAppDataPath, UserAppDataPath, etc. – no instances, all members are static class MyApp { public static void Main() { MyForm form = new MyForm(); start application Application.Run(form); } } 6
 - Form • Form class represents window, provides appropriate services – properties: Size, Location, Controls, ShowInTaskbar – methods: Show, Close, SetDesktopLocation – events: Load, Click, Closing • Common to derive from Form to create custom form define custom form class MyForm : Form { public MyForm() { this.ShowInTaskbar = false; set properties this.Location = new Point(10, 10); this.Size = new Size(100, 100); } } 7
 - Form border • Forms can look like windows, dialogs, or tools – controlled using FormBorderStyle property – set ShowInTaskbar property to false for tool windows – window border styles show the icon from the Icon property 8
 - Form properties • Form has many properties – used to customize appearance and behavior public class Form : ContainerControl { public IButtonControl AcceptButton { get; set; } public IButtonControl CancelButton { get; set; } public bool HelpButton { get; set; } public Icon Icon { get; set; } public String Text { get; set; } public Size MaximumSize { get; set; } properties public Size MinimumSize { get; set; } public MainMenu Menu { get; set; } public bool ShowInTaskbar { get; set; } public FormBorderStyle FormBorderStyle { get; set; } ... } 9
 - Form as container • Form manages a list of controls – stored in Controls collection property all forms inherit class MyForm : Form Controls collection { Button button1 = new Button(); Label label1 = new Label (); public MyForm() { ... this.Controls.Add(button1); add to collection this.Controls.Add(label1 ); } ... } myForm Controls button1 label1 10
 - Form layout • Form determines layout for controls it manages – recalculates as needed, such as when user resizes form – tries to accommodate control preferences for size and location – uses Anchor and Dock property of each control – can override OnLayout method to do custom layout resize 11
 - Controls • Controls are visual components derived from Control class – common controls supplied Object Component Control ButtonBase DataGrid ScrollableControl Button DateTimePicker ContainerControl CheckBox GroupBox Form RadioButton Label PropertyGrid UserControl MonthCalendar ListControl ComboBox PictureBox Panel TabPage ListBox ProgressBar Splitter StatusBar 12
 - Control properties • Controls supply many properties – used to customize appearance and behavior public class MyForm : Form { private Button button1; public MyForm() { button1 = new Button(); button1.Name = "OK button"; set properties button1.Text = "OK"; ... } } 13
 - Control events • Controls offer events – click – mouse or keyboard activity – property value change – paint – etc. public class Control : Component ... { public event EventHandler Click; public event EventHandler Enter; public event EventHandler TextChanged; events public event KeyPressEventHandler KeyPress; public event MouseEventHandler MouseDown; public event PaintEventHandler Paint; ... } 14
 - Event handlers • Several types of event handler delegates – generic EventHandler used for many events – specific types for some events such as mouse and keyboard • Event handlers have 2 arguments – control that generated event – event details in EventArgs or derived object delegate void EventHandler (object sender, EventArgs e); delegate void MouseEventHandler (object sender, MouseEventArgs e); delegate void KeyPressEventHandler(object sender, KeyPressEventArgs e); the control that event details generated the event 15
 - EventArgs • Event handlers pass event details to handler – passed in EventArgs or derived class object generic base class public class EventArgs so no event data { } info specific to class MouseEventArgs : EventArgs mouse event { public MouseButtons Button { get; } public int Clicks { get; } public int X { get; } public int Y { get; } ... } info specific to class KeyPressEventArgs : EventArgs keyboard event { public char KeyChar { get; } ... } 16
 - Event registration • Clients can register for events – define method with signature required by delegate – create delegate instance and add to event public class MyForm : Form { private Button button1; define void button1_Click(object sender, EventArgs args) method { ... } public MyForm() { ... register button1.Click += new EventHandler(this.button1_Click); ... } } 17
 - Components • Components are non-visual elements useful in UI – e.g. Timer, FileSystemWatcher, EventLog, etc. – extend System.ComponentModel.Component components in toolbox shown in component tray when added to form 18
 - Threading • Control should only be accessed by the creating thread – messages from different threads subject to interleaving – resulting race conditions can lead to inconsistent behavior • Control class provides methods for thread-switching – see docs for InvokeRequired, Invoke, BeginInvoke window message queue dequeue owning other thread thread access Login access window Name: controls Password: OK Cancel 19
 - No-touch deployment • Windows forms applications can be deployed automatically – client uses browser to access executable – needed assemblies downloaded and stored in download cache – program runs locally – executable downloaded only if changed since last run Client GET /App.exe HTTP/1.1 Server cache App.exe App.exe 20
 
	 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
ERROR:connection to 10.20.1.100:9315 failed (errno=111, msg=Connection refused)
ERROR:connection to 10.20.1.100:9315 failed (errno=111, msg=Connection refused)
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