Focus

 

Project StandardControls

These controls will be demonstrated in a project named StandardControls. This project is located at Visual Studio 2005\Projects\Demos-SourceCode\StandardControls. Move to the desktop, and open this project in the IDE. A section of the code in StandardControls is given as each control is discussed.

The main window looks like this:

image from book
Figure 19-1: Standard Controls window

This main window has a group box (with the text All ) that must be installed on the window template before any of the radio buttons or the Go! button. All of the controls shown in this chapter are taken from the Toolbox and are transferred to the appropriate template by clicking on the control s icon in the Toolbox, then moving the mouse pointer over the window template and clicking again.

Once the user has selected an item from the controls list, the Go! button is clicked to move to the proper controls demo. The code for the main window is shown below in lines SC0002-SC0221.

StandardControls (SC) Partial Listing

 Form1.cs: SC0002:       using System; SC0003:       using System.Collections.Generic; SC0004:       using System.ComponentModel; SC0005:       using System.Data; SC0006:       using System.Drawing; SC0007:       using System.Windows.Forms; SC0009:       namespace StandardControls SC0010:       { SC0011:         partial class Form1 : Form SC0012:         {                   // Create persistent storage for Form2. SC0013:           public string strForm2EditBox; SC0014:           public string strForm2RichEditBox; SC0015:           public Form1() SC0016:           {InitializeComponent(); } //-----------------------------------------------------------------------------------------// SC0020:           private void button1_Click(object sender, EventArgs e) SC0021:           { // Go! SC0022:             if(radioButton1.Checked)              // 1. Edit Controls. SC0023:             { // Create the Form2 modal window. SC0024:               // 'this' sends Form1 handle to Form2. SC0025:               Form2 frm2 = new Form2(this); SC0026:               frm2.ShowDialog(); SC0027:               frm2.Close(); SC0028:             } SC0029:             else if(radioButton2.Checked)         // 2. Radio Buttons. SC0030:             { // Create the Form3 modal window. SC0031:               Form3 frm3 = new Form3(); SC0032:               frm3.ShowDialog(); SC0033:               frm3.Close(); SC0034:             } SC0035:             else if(radioButton3.Checked)         // 3. Check Boxes. SC0036:             { // Create the Form4 modal window. SC0037:               Form4 frm4 = new Form4(); SC0038:               frm4.ShowDialog(); SC0039:               frm4.Close(); SC0040:             } SC0041:             else if(radioButton4.Checked)         // 4. List Boxes. SC0042:             { // Create the Form5 modal window. SC0043:               Form5 frm5 = new Form5(); SC0044:               frm5.ShowDialog(); SC0045:               frm5.Close(); SC0046:             } SC0047:             else if(radioButton5.Checked)         // 5. Combo Boxes. SC0048:             { // Create the Form6 modal window. SC0049:               Form6 frm6 = new Form6(); SC0050:               frm6.ShowDialog(); SC0051:               frm6.Close(); SC0052:             } SC0053:             else if(radioButton6.Checked)         // 6. Group Boxes. SC0054:             { // Create the Form7 modal window. SC0055:               Form7 frm7 = new Form7(); SC0056:               frm7.ShowDialog(); SC0057:               frm7.Close(); SC0058:             } SC0059:             else if(radioButton7.Checked)         // 7. Tab Controls. SC0060:             { // Create the Form8 modal window. SC0061:               Form8 frm8 = new Form8(); SC0062:               frm8.ShowDialog(); SC0063:               frm8.Close(); SC0064:             } SC0065:           } //-----------------------------------------------------------------------------------------// SC0070:           private void button2_Click(object sender, EventArgs e) SC0071:           { // Quit. SC0072:             Close(); SC0073:           } SC0074:         } SC0075:       } //=========================================================================================// Form1.Designer.cs: SC0090: SC0091:       namespace StandardControls SC0092:       { SC0093:         partial class Form1 SC0094:         {                   // Required designer variable. SC0095:           private System.ComponentModel.IContainer components = null;                   // Clean up any resources being used. SC0096:           protected override void Dispose(bool disposing) SC0097:           { SC0098:             if (disposing && (components != null)) components.Dispose(); SC0099:             base.Dispose(disposing); SC0100:           } SC0101:           #region Windows Form Designer generated code                   // Required method for Designer support. SC0102:           private void InitializeComponent() SC0103:           { SC0104:             this.label1 = new System.Windows.Forms.Label(); SC0105:             this.groupBox1 = new System.Windows.Forms.GroupBox(); SC0106:             this.radioButton1 = new System.Windows.Forms.RadioButton(); SC0107:             this.radioButton2 = new System.Windows.Forms.RadioButton(); SC0108:             this.radioButton3 = new System.Windows.Forms.RadioButton(); SC0109:             this.radioButton4 = new System.Windows.Forms.RadioButton(); SC0110:             this.radioButton5 = new System.Windows.Forms.RadioButton(); SC0111:             this.radioButton6 = new System.Windows.Forms.RadioButton(); SC0112:             this.radioButton7 = new System.Windows.Forms.RadioButton(); SC0113:             this.button1 = new System.Windows.Forms.Button(); SC0114:             this.button2 = new System.Windows.Forms.Button(); SC0115:             this.groupBox1.SuspendLayout(); SC0116:             this.SuspendLayout();                     //                     // label1                     // SC0117:             this.label1.AutoSize = true; SC0118:             this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 14F,                       System.Drawing.FontStyle.Underline, System.Drawing.GraphicsUnit.Point,                       ((byte)(0))); SC0119:             this.label1.Location = new System.Drawing.Point(90, 16); SC0120:             this.label1.Name = "label1"; SC0121:             this.label1.Size = new System.Drawing.Size(162, 24); SC0122:             this.label1.TabIndex = 0; SC0123:             this.label1.Text = "Standard Controls";                     //                     // groupBox1                     // SC0124:             this.groupBox1.Controls.Add(this.button1); SC0125:             this.groupBox1.Controls.Add(this.radioButton7); SC0126:             this.groupBox1.Controls.Add(this.radioButton6); SC0127:             this.groupBox1.Controls.Add(this.radioButton5); SC0128:             this.groupBox1.Controls.Add(this.radioButton4); SC0129:             this.groupBox1.Controls.Add(this.radioButton3); SC0130:             this.groupBox1.Controls.Add(this.radioButton2); SC0131:             this.groupBox1.Controls.Add(this.radioButton1); SC0132:             this.groupBox1.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F,                       System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,                       ((byte)(0))); SC0133:             this.groupBox1.Location = new System.Drawing.Point(75, 48); SC0134:             this.groupBox1.Name = "groupBox1"; SC0135:             this.groupBox1.Size = new System.Drawing.Size(200, 259); SC0136:             this.groupBox1.TabIndex = 1; SC0137:             this.groupBox1.TabStop = false; SC0138:             this.groupBox1.Text = "All";                     //                     // radioButton1                     // SC0139:             this.radioButton1.AutoSize = true; SC0140:             this.radioButton1.Location = new System.Drawing.Point(30, 25); SC0141:             this.radioButton1.Name = "radioButton1"; SC0142:             this.radioButton1.Size = new System.Drawing.Size(122, 21); SC0143:             this.radioButton1.TabIndex = 0; SC0144:             this.radioButton1.Text = "1. Edit Controls";                     [radioButtons 2, 3, 4, 5, 6, 7]                     //                     // button1                     // SC0185:             this.button1.Location = new System.Drawing.Point(62, 210); SC0186:             this.button1.Name = "button1"; SC0187:             this.button1.TabIndex = 7; SC0188:             this.button1.Text = "Go !"; SC0189:             this.button1.Click += new System.EventHandler(this.button1_Click);                     //                     // button2                     // SC0190:             this.button2.Location = new System.Drawing.Point(48, 318); SC0191:             this.button2.Name = "button2"; SC0192:             this.button2.TabIndex = 2; SC0193:             this.button2.Text = "Quit"; SC0194:             this.button2.Click += new System.EventHandler(this.button2_Click);                     //                     // Form1                     // SC0195:             this.AutoScaleDimensions = new System.Drawing.SizeF(5F, 13F); SC0196:             this.ClientSize = new System.Drawing.Size(334, 352); SC0197:             this.Controls.Add(this.button2); SC0198:             this.Controls.Add(this.groupBox1); SC0199:             this.Controls.Add(this.label1); SC0200:             this.Name = "Form1"; SC0201:             this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; SC0203:             this.groupBox1.ResumeLayout(false); SC0202:             this.Text = "Standard Controls"; SC0204:             this.groupBox1.PerformLayout(); SC0205:             this.ResumeLayout(false); SC0206:             this.PerformLayout(); SC0207:           } SC0208:           #endregion SC0209:           private System.Windows.Forms.Label label1; SC0210:           private System.Windows.Forms.GroupBox groupBox1; SC0211:           private System.Windows.Forms.RadioButton radioButton1; SC0212:           private System.Windows.Forms.RadioButton radioButton2; SC0213:           private System.Windows.Forms.RadioButton radioButton3; SC0214:           private System.Windows.Forms.RadioButton radioButton4; SC0215:           private System.Windows.Forms.RadioButton radioButton5; SC0216:           private System.Windows.Forms.RadioButton radioButton6; SC0217:           private System.Windows.Forms.RadioButton radioButton7; SC0218:           private System.Windows.Forms.Button button1; SC0219:           private System.Windows.Forms.Button button2; SC0220:         } SC0221:       } 
 


Unlocking Microsoft C# V 2.0 Programming Secrets
Unlocking Microsoft C# V 2.0 Programming Secrets (Wordware Applications Library)
ISBN: 1556220979
EAN: 2147483647
Year: 2005
Pages: 129

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net