.NET 範例 - Windows Form:撰寫控制項
這個章節包括下列範例:
UserControl 範例
LicensedControl 範例
SimpleControl 範例
Hello World 控制項範例
CustomUITypeEditor 範例
HelpLabel 範例
UserControl 範例
這個範例示範藉由擴充 System.Windows.Forms.UserControl 的方式建立使用者控制項。使用者控制項提供比一般控制項更為固有的功能,所以使用者不必像為捲動和作為控制項容器使用的各種功能那樣,在程式中使用那麼多邏輯。
連結到線上範例文件
連結到線上範例原始程式碼
這個範例中所用的命名空間:
(無)
這個範例中所用的類別:
(無)
LicensedControl 範例
這個範例示範使用 License 物件以防止使用者控制項在未經授權的裝載容器中執行。
連結到線上範例文件
連結到線上範例原始程式碼
這個範例中所用的命名空間:
System;System.Drawing;System.ComponentModel;System.Windows.Forms
這個範例中所用的類別:
License;Control;Form;Component;Container;LicenseProvider;Font;LicFileLicenseProvider;Style;Application;Thread;Brush;Graphics;PaintEventArgs;LicenseProviderAttribute;SolidBrush;File;EventArgs;String;LicenseManager;Attribute
SimpleControl 範例
這個範例示範控制項撰寫屬性的用法,以便和 Visual Studio 設計工具互動。在這個範例中,如果有說明和預設值,就可以在瀏覽器中看到控制項的各種屬性。
連結到線上範例文件
連結到線上範例原始程式碼
這個範例中所用的命名空間:
System;System.Drawing;System.Windows.Forms;System.ComponentModel
這個範例中所用的類別:
Button;Control;Form;EventArgs;Font;Component;EventHandler;RadioButton;Style;MessageBox;Message;Graphics;Brush;Group;GroupBox;Container;SolidBrush;String;Thread;FontFamily;Icon;PaintEventArgs;Application
Hello World 控制項範例
這個範例說明基本的 Windows Form 控制項所需的程式碼。程式碼衍生自 System.Windows.Forms.Control,而且會覆寫 OnPaint 事件,所以控制項可以用自訂方式繪製其用戶端區域。
連結到線上範例文件
連結到線上範例原始程式碼
這個範例中所用的命名空間:
System;System.Drawing;System.Windows.Forms;System.ComponentModel
這個範例中所用的類別:
Control;Form;Font;Component;Style;Container;Application;String;EventArgs;Brush;Thread;Icon;Graphics;SolidBrush;PaintEventArgs;FontFamily
CustomUITypeEditor 範例
這個範例示範實作自訂 UI 型別編輯器所需的程式碼。這個範例會為 FlashTrackBar
控制項建立型別編輯器,以便在使用者編輯 FlashTrackBar
的各種屬性時,提供更好的檢視。
連結到線上範例文件
連結到線上範例原始程式碼
這個範例中所用的命名空間:
System;System.Drawing;System.Windows.Forms;System.ComponentModel;System.Drawing.Design;System.Diagnostics;System.ComponentModel.Design;System.Drawing.Drawing2D;System.Windows.Forms.Design
這個範例中所用的類別:
TrackBar;Font;Form;Component;EventArgs;Style;String;Instance;Type;Control;Graphics;Brush;Convert;UITypeEditor;Service;Container;Capture;Image;MouseEventArgs;EventHandler;SolidBrush;Context;Math;TypeDescriptor;Application;Icon;Thread;LinearGradientBrush;PaintEventArgs;TextureBrush;Debug
HelpLabel 範例
這個範例示範簡單的擴充項提供者 (Extender Provider)。當擴充項提供者加入表單時,所有其他控制項都可以從擴充項提供者得到屬性。這個範例將 HelpText 屬性加入每個控制項中,可以在指標移到控制項上時,提供 [說明] 快顯視窗 (Pop-up Window)。
連結到線上範例文件
連結到線上範例原始程式碼
這個範例中所用的命名空間:
System;System.Drawing;System.Windows.Forms;System.ComponentModel;System.Windows.Forms.Design;System.ComponentModel.Design;System.Collections
這個範例中所用的類別:
Label;Control;Help;Form;Service;Component;EventHandler;Style;EventArgs;DesignerVerb;Pen;Button;SystemColors;Container;Type;TextBox;TypeDescriptor;Hashtable;Hash;Graphics;DesignerVerbCollection;Brush;Attribute;SolidBrush;Thread;Message;Font;MessageBox;PaintEventArgs;String;Icon;CategoryAttribute;Application