using System; using System.Collections; using System.ComponentModel; using System.Drawing; using System.Data; using System.Windows.Forms; public class CompoundControl : System.Windows.Forms.UserControl { public delegate Boolean ValueChangedEventHandler(int nValue); private System.Windows.Forms.Label label1; private System.Windows.Forms.ComboBox comboBox1; public event ValueChangedEventHandler Changed; public CompoundControl() { this.comboBox1 = new System.Windows.Forms.ComboBox(); this.label1 = new System.Windows.Forms.Label(); this.SuspendLayout(); this.comboBox1.DropDownWidth = 121; this.comboBox1.Items.AddRange(new object[] {"A","B","C","F","G","N"}); this.comboBox1.Location = new System.Drawing.Point(24, 48); this.comboBox1.Size = new System.Drawing.Size(200, 21); this.comboBox1.Text = "comboBox1"; this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.OnSelectionIndexChange); this.label1.Location = new System.Drawing.Point(16, 24); this.label1.Text = "Select An Entry"; this.Controls.AddRange(new System.Windows.Forms.Control[] { this.comboBox1, this.label1}); this.Size = new System.Drawing.Size(240, 96); this.ResumeLayout(false); } private void OnSelectionIndexChange(object sender, System.EventArgs e) { if (Changed != null) Changed(this.comboBox1.SelectedIndex); } } public class Form1 : System.Windows.Forms.Form { private System.ComponentModel.Container components = null; private CompoundControl compoundcomponent1 = null; public Form1() { this.compoundcomponent1 = new CompoundControl(); this.compoundcomponent1.Location = new System.Drawing.Point(24, 50); this.compoundcomponent1.Name = "compound1"; this.compoundcomponent1.Size = new System.Drawing.Size(250, 100); this.compoundcomponent1.Changed += new CompoundControl.ValueChangedEventHandler(OnChanged); this.components = new System.ComponentModel.Container(); this.Size = new System.Drawing.Size(300, 300); this.Controls.AddRange(new System.Windows.Forms.Control[]{this.compoundcomponent1,}); } private bool OnChanged(int nIndex) { MessageBox.Show(this, "New Index!" + nIndex); return true; } [STAThread] static void Main() { Application.Run(new Form1()); } }
The read-only property control.
using System; using System.Collections; using System.ComponentModel; using System.Drawing; using System.Data; using System.Windows.Forms; public class TimerCounter : System.Windows.Forms.UserControl { private System.Windows.Forms.Timer timer1; private System.ComponentModel.IContainer components; private int fCounter = 0; public int Counter { get { return fCounter; } } public TimerCounter() { this.components = new System.ComponentModel.Container(); this.timer1 = new System.Windows.Forms.Timer(this.components); this.timer1.Enabled = true; this.timer1.Interval = 1000; this.timer1.Tick += new System.EventHandler(this.OnTick); this.Name = "TimerCounter"; } private void OnTick(object sender, System.EventArgs e) { fCounter++; } } public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.Label label1 = new System.Windows.Forms.Label(); private System.Windows.Forms.Label CounterLabel; private System.Windows.Forms.Button Update; private System.ComponentModel.Container components = null; private TimerCounter counter; public Form1() { counter = new TimerCounter(); this.CounterLabel = new System.Windows.Forms.Label(); this.Update = new System.Windows.Forms.Button(); this.SuspendLayout(); this.label1.Location = new System.Drawing.Point(32, 24); this.label1.Size = new System.Drawing.Size(48, 23); this.label1.Text = "Counter: "; this.CounterLabel.Location = new System.Drawing.Point(96, 24); this.CounterLabel.Size = new System.Drawing.Size(32, 23); this.Update.Location = new System.Drawing.Point(80, 72); this.Update.Text = "Update"; this.Update.Click += new System.EventHandler(this.Update_Click); this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(224, 133); this.Controls.AddRange(new System.Windows.Forms.Control[] {this.Update,this.CounterLabel,this.label1}); this.ResumeLayout(false); } [STAThread] static void Main() { Application.Run(new Form1()); } private void Update_Click(object sender, System.EventArgs e) { CounterLabel.Text = counter.Counter.ToString(); } }
Numeric value based Up Down (Spinner)
using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; public class UpDownForm : System.Windows.Forms.Form { private System.Windows.Forms.Label lblCurrSel; private System.Windows.Forms.Button btnGetSelections; private System.Windows.Forms.Label label1; private System.Windows.Forms.NumericUpDown numericUpDown; public UpDownForm() { InitializeComponent(); } private void InitializeComponent() { this.label1 = new System.Windows.Forms.Label (); this.numericUpDown = new System.Windows.Forms.NumericUpDown (); this.btnGetSelections = new System.Windows.Forms.Button (); this.lblCurrSel = new System.Windows.Forms.Label (); numericUpDown.BeginInit (); label1.Location = new System.Drawing.Point (8, 80); label1.Text = "Numeric UpDown Control"; label1.Size = new System.Drawing.Size (232, 32); label1.Font = new System.Drawing.Font ("Verdana", 12); label1.TabIndex = 3; numericUpDown.Location = new System.Drawing.Point (264, 80); numericUpDown.Maximum = new decimal (5000); numericUpDown.Size = new System.Drawing.Size (168, 20); numericUpDown.ThousandsSeparator = true; numericUpDown.TabIndex = 1; numericUpDown.UpDownAlign = System.Windows.Forms.LeftRightAlignment.Left; numericUpDown.ValueChanged += new System.EventHandler (this.numericUpDown_ValueChanged); btnGetSelections.Location = new System.Drawing.Point (16, 136); btnGetSelections.Size = new System.Drawing.Size (136, 24); btnGetSelections.TabIndex = 4; btnGetSelections.Text = "Get Current Selections"; btnGetSelections.Click += new System.EventHandler (this.btnGetSelections_Click); lblCurrSel.Location = new System.Drawing.Point (176, 120); lblCurrSel.Size = new System.Drawing.Size (256, 48); this.Text = "Spin Controls"; this.AutoScaleBaseSize = new System.Drawing.Size (5, 13); this.ClientSize = new System.Drawing.Size (448, 181); this.Controls.Add (this.lblCurrSel); this.Controls.Add (this.btnGetSelections); this.Controls.Add (this.label1); this.Controls.Add (this.numericUpDown); numericUpDown.EndInit (); } static void Main() { Application.Run(new UpDownForm()); } protected void numericUpDown_ValueChanged (object sender, System.EventArgs e) { this.Text = "You changed the numeric value..."; } protected void btnGetSelections_Click (object sender, System.EventArgs e) { lblCurrSel.Text = "Number: " + numericUpDown.Value; } }
String based DomainUpDown (Spinner)
using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; public class UpDownForm : System.Windows.Forms.Form { private System.Windows.Forms.Label lblCurrSel; private System.Windows.Forms.Button btnGetSelections; private System.Windows.Forms.Label label1; private System.Windows.Forms.DomainUpDown domainUpDown; public UpDownForm() { InitializeComponent(); } private void InitializeComponent() { this.label1 = new System.Windows.Forms.Label (); this.domainUpDown = new System.Windows.Forms.DomainUpDown (); this.btnGetSelections = new System.Windows.Forms.Button (); this.lblCurrSel = new System.Windows.Forms.Label (); label1.Location = new System.Drawing.Point (8, 24); label1.Text = "Domain UpDown Control"; label1.Size = new System.Drawing.Size (224, 32); label1.Font = new System.Drawing.Font ("Verdana", 12); label1.TabIndex = 2; domainUpDown.Location = new System.Drawing.Point (264, 24); domainUpDown.Text = "domainUpDown1"; domainUpDown.Size = new System.Drawing.Size (168, 20); domainUpDown.TabIndex = 0; domainUpDown.Sorted = true; domainUpDown.Wrap = true; domainUpDown.SelectedItemChanged += new System.EventHandler (this.domainUpDown_SelectedItemChanged); domainUpDown.Items.AddRange(new object[4] {"B", "A", "C", "(D)"}); btnGetSelections.Location = new System.Drawing.Point (16, 136); btnGetSelections.Size = new System.Drawing.Size (136, 24); btnGetSelections.TabIndex = 4; btnGetSelections.Text = "Get Current Selections"; btnGetSelections.Click += new System.EventHandler (this.btnGetSelections_Click); lblCurrSel.Location = new System.Drawing.Point (176, 120); lblCurrSel.Size = new System.Drawing.Size (256, 48); this.Text = "Spin Controls"; this.AutoScaleBaseSize = new System.Drawing.Size (5, 13); this.ClientSize = new System.Drawing.Size (448, 181); this.Controls.Add (this.lblCurrSel); this.Controls.Add (this.btnGetSelections); this.Controls.Add (this.label1); this.Controls.Add (this.domainUpDown); } static void Main() { Application.Run(new UpDownForm()); } protected void domainUpDown_SelectedItemChanged (object sender, System.EventArgs e) { this.Text = "You changed the string value..."; } protected void btnGetSelections_Click (object sender, System.EventArgs e) { // Get info from updowns... lblCurrSel.Text = "String: " + domainUpDown.Text ; } }
Unicode encoding: Japanese
using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; public class Unicode : System.Windows.Forms.Form { System.Windows.Forms.Label myLabel = new System.Windows.Forms.Label(); public Unicode() { this.SuspendLayout(); this.myLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 50.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))); this.myLabel.Location = new System.Drawing.Point(20, 20); this.myLabel.Size = new System.Drawing.Size(800, 800); this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(800, 200); this.Controls.AddRange(new System.Windows.Forms.Control[] {this.myLabel}); this.Name = "Unicode"; this.Text = "Unicode"; this.Load += new System.EventHandler(this.Unicode_Load); this.ResumeLayout(false); } [STAThread] static void Main() { Application.Run(new Unicode()); } private void Unicode_Load(object sender, System.EventArgs e) { // Japanese char[] japanese = { 'u3078', 'u3087', 'u3045', 'u3053', 'u305D', 'u0021'}; myLabel.Text = new string(japanese) + "Unicode" + 'u0021'; } }
Unicode encoding:
using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; public class Unicode : System.Windows.Forms.Form { System.Windows.Forms.Label myLabel = new System.Windows.Forms.Label(); public Unicode() { this.SuspendLayout(); this.myLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 50.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))); this.myLabel.Location = new System.Drawing.Point(20, 20); this.myLabel.Size = new System.Drawing.Size(800, 800); this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(800, 200); this.Controls.AddRange(new System.Windows.Forms.Control[] {this.myLabel}); this.Name = "Unicode"; this.Text = "Unicode"; this.Load += new System.EventHandler(this.Unicode_Load); this.ResumeLayout(false); } [STAThread] static void Main() { Application.Run(new Unicode()); } private void Unicode_Load(object sender, System.EventArgs e) { // Portuguese char[] portuguese = {'u0053', 'u0065', 'u006A', 'u0061', 'u0020', 'u0062', 'u0065', 'u006D', 'u0020', 'u0076', 'u0069', 'u006E', 'u0064', 'u006F', 'u0020', 'u0061', 'u0020' }; myLabel.Text = new string(portuguese) + "Unicode" + 'u0021'; } }
Unicode encoding: Russian
using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; public class Unicode : System.Windows.Forms.Form { System.Windows.Forms.Label myLabel = new System.Windows.Forms.Label(); public Unicode() { this.SuspendLayout(); this.myLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 50.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))); this.myLabel.Location = new System.Drawing.Point(20, 20); this.myLabel.Size = new System.Drawing.Size(800, 800); this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(800, 200); this.Controls.AddRange(new System.Windows.Forms.Control[] {this.myLabel}); this.Name = "Unicode"; this.Text = "Unicode"; this.Load += new System.EventHandler(this.Unicode_Load); this.ResumeLayout(false); } [STAThread] static void Main() { Application.Run(new Unicode()); } private void Unicode_Load(object sender, System.EventArgs e) { // Russian char[] russian = { 'u0414', 'u043E', 'u0431', 'u0440', 'u043E', 'u0020', 'u043F', 'u043E', 'u0436', 'u0430', 'u043B', 'u043E', 'u0432', 'u0430', 'u0442', 'u044A', 'u0020', 'u0432', 'u0020' }; myLabel.Text = new string(russian) + "Unicode" + 'u0021'; } }