[C#][SAMPLE][CODE][Control]RadioBox、CheckBox和Validating事件的相关处理

本文介绍了一个C#窗体验证的示例程序,演示了如何使用TextBox、CheckBox及RadioButton控件,并通过Validating事件确保输入的有效性。示例还展示了如何在用户输入不完整时进行提示。
[示例出处]:本示例来自《C#入门经典》第三版中文版,P349-P353
[示例涉及]:
1、RadioBox、CheckBox控件的基本使用
2、Validating事件的使用(同 [C#][SAMPLE][CODE][Control]TextBox和Validating事件的相关处理 )
3、多委托处理同一事件方法(同 [C#][SAMPLE][CODE][Control]TextBox和Validating事件的相关处理 )
[示例代码]:2文件(其余默认)

Form1.Designer.cs
  1 None.gif namespace  WA_TextBoxTest
  2 ExpandedBlockStart.gifContractedBlock.gif dot.gif {
  3InBlock.gif    partial class Form1
  4ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
  5ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
  6InBlock.gif        /// 必需的设计器变量。
  7ExpandedSubBlockEnd.gif        /// </summary>

  8InBlock.gif        private System.ComponentModel.IContainer components = null;
  9InBlock.gif
 10ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
 11InBlock.gif        /// 清理所有正在使用的资源。
 12InBlock.gif        /// </summary>
 13ExpandedSubBlockEnd.gif        /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>

 14InBlock.gif        protected override void Dispose(bool disposing)
 15ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 16InBlock.gif            if (disposing && (components != null))
 17ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 18InBlock.gif                components.Dispose();
 19ExpandedSubBlockEnd.gif            }

 20InBlock.gif            base.Dispose(disposing);
 21ExpandedSubBlockEnd.gif        }

 22InBlock.gif
 23ContractedSubBlock.gifExpandedSubBlockStart.gif        Windows 窗体设计器生成的代码#region Windows 窗体设计器生成的代码
 24InBlock.gif
 25ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
 26InBlock.gif        /// 设计器支持所需的方法 - 不要
 27InBlock.gif        /// 使用代码编辑器修改此方法的内容。
 28ExpandedSubBlockEnd.gif        /// </summary>

 29InBlock.gif        private void InitializeComponent()
 30ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 31InBlock.gif            this.label1 = new System.Windows.Forms.Label();
 32InBlock.gif            this.label2 = new System.Windows.Forms.Label();
 33InBlock.gif            this.textBoxName = new System.Windows.Forms.TextBox();
 34InBlock.gif            this.textBoxAddress = new System.Windows.Forms.TextBox();
 35InBlock.gif            this.textBoxAge = new System.Windows.Forms.TextBox();
 36InBlock.gif            this.textBoxOutput = new System.Windows.Forms.TextBox();
 37InBlock.gif            this.label4 = new System.Windows.Forms.Label();
 38InBlock.gif            this.label5 = new System.Windows.Forms.Label();
 39InBlock.gif            this.buttonOK = new System.Windows.Forms.Button();
 40InBlock.gif            this.buttonHelp = new System.Windows.Forms.Button();
 41InBlock.gif            this.checkBoxProgrammer = new System.Windows.Forms.CheckBox();
 42InBlock.gif            this.groupBoxSex = new System.Windows.Forms.GroupBox();
 43InBlock.gif            this.radioButtonMale = new System.Windows.Forms.RadioButton();
 44InBlock.gif            this.radioButtonFemale = new System.Windows.Forms.RadioButton();
 45InBlock.gif            this.groupBoxSex.SuspendLayout();
 46InBlock.gif            this.SuspendLayout();
 47InBlock.gif            // 
 48InBlock.gif            // label1
 49InBlock.gif            // 
 50InBlock.gif            this.label1.AutoSize = true;
 51InBlock.gif            this.label1.Location = new System.Drawing.Point(2627);
 52InBlock.gif            this.label1.Name = "label1";
 53InBlock.gif            this.label1.Size = new System.Drawing.Size(5912);
 54InBlock.gif            this.label1.TabIndex = 0;
 55InBlock.gif            this.label1.Text = "labelName";
 56InBlock.gif            // 
 57InBlock.gif            // label2
 58InBlock.gif            // 
 59InBlock.gif            this.label2.AutoSize = true;
 60InBlock.gif            this.label2.Location = new System.Drawing.Point(2653);
 61InBlock.gif            this.label2.Name = "label2";
 62InBlock.gif            this.label2.Size = new System.Drawing.Size(7712);
 63InBlock.gif            this.label2.TabIndex = 1;
 64InBlock.gif            this.label2.Text = "labelAddress";
 65InBlock.gif            // 
 66InBlock.gif            // textBoxName
 67InBlock.gif            // 
 68InBlock.gif            this.textBoxName.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
 69InBlock.gif                        | System.Windows.Forms.AnchorStyles.Right)));
 70InBlock.gif            this.textBoxName.Location = new System.Drawing.Point(12724);
 71InBlock.gif            this.textBoxName.Name = "textBoxName";
 72InBlock.gif            this.textBoxName.Size = new System.Drawing.Size(31721);
 73InBlock.gif            this.textBoxName.TabIndex = 2;
 74InBlock.gif            // 
 75InBlock.gif            // textBoxAddress
 76InBlock.gif            // 
 77InBlock.gif            this.textBoxAddress.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
 78InBlock.gif                        | System.Windows.Forms.AnchorStyles.Right)));
 79InBlock.gif            this.textBoxAddress.Location = new System.Drawing.Point(12750);
 80InBlock.gif            this.textBoxAddress.Multiline = true;
 81InBlock.gif            this.textBoxAddress.Name = "textBoxAddress";
 82InBlock.gif            this.textBoxAddress.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
 83InBlock.gif            this.textBoxAddress.Size = new System.Drawing.Size(317102);
 84InBlock.gif            this.textBoxAddress.TabIndex = 2;
 85InBlock.gif            // 
 86InBlock.gif            // textBoxAge
 87InBlock.gif            // 
 88InBlock.gif            this.textBoxAge.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
 89InBlock.gif                        | System.Windows.Forms.AnchorStyles.Right)));
 90InBlock.gif            this.textBoxAge.Location = new System.Drawing.Point(127254);
 91InBlock.gif            this.textBoxAge.Name = "textBoxAge";
 92InBlock.gif            this.textBoxAge.Size = new System.Drawing.Size(9921);
 93InBlock.gif            this.textBoxAge.TabIndex = 4;
 94InBlock.gif            this.textBoxAge.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBoxAge_KeyPress);
 95InBlock.gif            // 
 96InBlock.gif            // textBoxOutput
 97InBlock.gif            // 
 98InBlock.gif            this.textBoxOutput.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
 99InBlock.gif                        | System.Windows.Forms.AnchorStyles.Left)
100InBlock.gif                        | System.Windows.Forms.AnchorStyles.Right)));
101InBlock.gif            this.textBoxOutput.Location = new System.Drawing.Point(28307);
102InBlock.gif            this.textBoxOutput.Multiline = true;
103InBlock.gif            this.textBoxOutput.Name = "textBoxOutput";
104InBlock.gif            this.textBoxOutput.ReadOnly = true;
105InBlock.gif            this.textBoxOutput.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
106InBlock.gif            this.textBoxOutput.Size = new System.Drawing.Size(416171);
107InBlock.gif            this.textBoxOutput.TabIndex = 5;
108InBlock.gif            // 
109InBlock.gif            // label4
110InBlock.gif            // 
111InBlock.gif            this.label4.AutoSize = true;
112InBlock.gif            this.label4.Location = new System.Drawing.Point(26257);
113InBlock.gif            this.label4.Name = "label4";
114InBlock.gif            this.label4.Size = new System.Drawing.Size(5312);
115InBlock.gif            this.label4.TabIndex = 7;
116InBlock.gif            this.label4.Text = "labelAge";
117InBlock.gif            // 
118InBlock.gif            // label5
119InBlock.gif            // 
120InBlock.gif            this.label5.AutoSize = true;
121InBlock.gif            this.label5.Location = new System.Drawing.Point(26289);
122InBlock.gif            this.label5.Name = "label5";
123InBlock.gif            this.label5.Size = new System.Drawing.Size(7112);
124InBlock.gif            this.label5.TabIndex = 8;
125InBlock.gif            this.label5.Text = "labelOutput";
126InBlock.gif            // 
127InBlock.gif            // buttonOK
128InBlock.gif            // 
129InBlock.gif            this.buttonOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
130InBlock.gif            this.buttonOK.Location = new System.Drawing.Point(45818);
131InBlock.gif            this.buttonOK.Name = "buttonOK";
132InBlock.gif            this.buttonOK.Size = new System.Drawing.Size(8221);
133InBlock.gif            this.buttonOK.TabIndex = 9;
134InBlock.gif            this.buttonOK.Text = "OK";
135InBlock.gif            this.buttonOK.UseVisualStyleBackColor = true;
136InBlock.gif            this.buttonOK.Click += new System.EventHandler(this.buttonOK_Click);
137InBlock.gif            // 
138InBlock.gif            // buttonHelp
139InBlock.gif            // 
140InBlock.gif            this.buttonHelp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
141InBlock.gif            this.buttonHelp.CausesValidation = false;
142InBlock.gif            this.buttonHelp.Location = new System.Drawing.Point(45843);
143InBlock.gif            this.buttonHelp.Name = "buttonHelp";
144InBlock.gif            this.buttonHelp.Size = new System.Drawing.Size(8221);
145InBlock.gif            this.buttonHelp.TabIndex = 10;
146InBlock.gif            this.buttonHelp.Text = "Help";
147InBlock.gif            this.buttonHelp.UseVisualStyleBackColor = true;
148InBlock.gif            this.buttonHelp.Click += new System.EventHandler(this.buttonHelp_Click);
149InBlock.gif            // 
150InBlock.gif            // checkBoxProgrammer
151InBlock.gif            // 
152InBlock.gif            this.checkBoxProgrammer.AutoSize = true;
153InBlock.gif            this.checkBoxProgrammer.Checked = true;
154InBlock.gif            this.checkBoxProgrammer.CheckState = System.Windows.Forms.CheckState.Checked;
155InBlock.gif            this.checkBoxProgrammer.Location = new System.Drawing.Point(28166);
156InBlock.gif            this.checkBoxProgrammer.Name = "checkBoxProgrammer";
157InBlock.gif            this.checkBoxProgrammer.Size = new System.Drawing.Size(8416);
158InBlock.gif            this.checkBoxProgrammer.TabIndex = 11;
159InBlock.gif            this.checkBoxProgrammer.Text = "Programmer";
160InBlock.gif            this.checkBoxProgrammer.UseVisualStyleBackColor = true;
161InBlock.gif            // 
162InBlock.gif            // groupBoxSex
163InBlock.gif            // 
164InBlock.gif            this.groupBoxSex.Controls.Add(this.radioButtonMale);
165InBlock.gif            this.groupBoxSex.Controls.Add(this.radioButtonFemale);
166InBlock.gif            this.groupBoxSex.Location = new System.Drawing.Point(28188);
167InBlock.gif            this.groupBoxSex.Name = "groupBoxSex";
168InBlock.gif            this.groupBoxSex.Size = new System.Drawing.Size(41555);
169InBlock.gif            this.groupBoxSex.TabIndex = 12;
170InBlock.gif            this.groupBoxSex.TabStop = false;
171InBlock.gif            this.groupBoxSex.Text = "Sex";
172InBlock.gif            // 
173InBlock.gif            // radioButtonMale
174InBlock.gif            // 
175InBlock.gif            this.radioButtonMale.AutoSize = true;
176InBlock.gif            this.radioButtonMale.Location = new System.Drawing.Point(23524);
177InBlock.gif            this.radioButtonMale.Name = "radioButtonMale";
178InBlock.gif            this.radioButtonMale.Size = new System.Drawing.Size(11316);
179InBlock.gif            this.radioButtonMale.TabIndex = 1;
180InBlock.gif            this.radioButtonMale.Text = "radioButtonMale";
181InBlock.gif            this.radioButtonMale.UseVisualStyleBackColor = true;
182InBlock.gif            // 
183InBlock.gif            // radioButtonFemale
184InBlock.gif            // 
185InBlock.gif            this.radioButtonFemale.AutoSize = true;
186InBlock.gif            this.radioButtonFemale.Checked = true;
187InBlock.gif            this.radioButtonFemale.Location = new System.Drawing.Point(5524);
188InBlock.gif            this.radioButtonFemale.Name = "radioButtonFemale";
189InBlock.gif            this.radioButtonFemale.Size = new System.Drawing.Size(12516);
190InBlock.gif            this.radioButtonFemale.TabIndex = 0;
191InBlock.gif            this.radioButtonFemale.TabStop = true;
192InBlock.gif            this.radioButtonFemale.Text = "radioButtonFemale";
193InBlock.gif            this.radioButtonFemale.UseVisualStyleBackColor = true;
194InBlock.gif            // 
195InBlock.gif            // Form1
196InBlock.gif            // 
197InBlock.gif            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
198InBlock.gif            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
199InBlock.gif            this.ClientSize = new System.Drawing.Size(561490);
200InBlock.gif            this.Controls.Add(this.groupBoxSex);
201InBlock.gif            this.Controls.Add(this.checkBoxProgrammer);
202InBlock.gif            this.Controls.Add(this.buttonHelp);
203InBlock.gif            this.Controls.Add(this.buttonOK);
204InBlock.gif            this.Controls.Add(this.label5);
205InBlock.gif            this.Controls.Add(this.label4);
206InBlock.gif            this.Controls.Add(this.textBoxOutput);
207InBlock.gif            this.Controls.Add(this.textBoxAge);
208InBlock.gif            this.Controls.Add(this.textBoxAddress);
209InBlock.gif            this.Controls.Add(this.textBoxName);
210InBlock.gif            this.Controls.Add(this.label2);
211InBlock.gif            this.Controls.Add(this.label1);
212InBlock.gif            this.Name = "Form1";
213InBlock.gif            this.Text = "Form1";
214InBlock.gif            this.Validating += new System.ComponentModel.CancelEventHandler(this.textBoxEmpty_Validating);
215InBlock.gif            this.groupBoxSex.ResumeLayout(false);
216InBlock.gif            this.groupBoxSex.PerformLayout();
217InBlock.gif            this.ResumeLayout(false);
218InBlock.gif            this.PerformLayout();
219InBlock.gif
220ExpandedSubBlockEnd.gif        }

221InBlock.gif
222ExpandedSubBlockEnd.gif        #endregion

223InBlock.gif
224InBlock.gif        private System.Windows.Forms.Label label1;
225InBlock.gif        private System.Windows.Forms.Label label2;
226InBlock.gif        private System.Windows.Forms.TextBox textBoxName;
227InBlock.gif        private System.Windows.Forms.TextBox textBoxAddress;
228InBlock.gif        private System.Windows.Forms.TextBox textBoxAge;
229InBlock.gif        private System.Windows.Forms.TextBox textBoxOutput;
230InBlock.gif        private System.Windows.Forms.Label label4;
231InBlock.gif        private System.Windows.Forms.Label label5;
232InBlock.gif        private System.Windows.Forms.Button buttonOK;
233InBlock.gif        private System.Windows.Forms.Button buttonHelp;
234InBlock.gif        private System.Windows.Forms.CheckBox checkBoxProgrammer;
235InBlock.gif        private System.Windows.Forms.GroupBox groupBoxSex;
236InBlock.gif        private System.Windows.Forms.RadioButton radioButtonMale;
237InBlock.gif        private System.Windows.Forms.RadioButton radioButtonFemale;
238ExpandedSubBlockEnd.gif    }

239ExpandedBlockEnd.gif}

240 None.gif
241 None.gif

Form1.cs
  1 None.gif using  System;
  2 None.gif using  System.Collections.Generic;
  3 None.gif using  System.ComponentModel;
  4 None.gif using  System.Data;
  5 None.gif using  System.Drawing;
  6 None.gif using  System.Text;
  7 None.gif using  System.Windows.Forms;
  8 None.gif
  9 None.gif namespace  WA_TextBoxTest
 10 ExpandedBlockStart.gifContractedBlock.gif dot.gif {
 11InBlock.gif    public partial class Form1 : Form
 12ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
 13InBlock.gif        public Form1()
 14ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 15InBlock.gif            InitializeComponent();
 16InBlock.gif            this.buttonOK.Enabled = false;
 17InBlock.gif
 18InBlock.gif            //Tag values for testing if the data is valid.
 19InBlock.gif            this.textBoxName.Tag = false;
 20InBlock.gif            this.textBoxAddress.Tag = false;
 21InBlock.gif            this.textBoxAge.Tag = false;
 22InBlock.gif
 23InBlock.gif            //订阅事件Subscriptions to events
 24InBlock.gif            this.textBoxName.Validating += new CancelEventHandler(this.textBoxEmpty_Validating);
 25InBlock.gif            this.textBoxAddress.Validating += new CancelEventHandler(this.textBoxEmpty_Validating);
 26InBlock.gif            this.textBoxAge.Validating += new CancelEventHandler(this.textBoxEmpty_Validating);
 27InBlock.gif
 28InBlock.gif            //当控件中文本发生改变,就激发TextChanged事件。
 29InBlock.gif            this.textBoxName.TextChanged +=new EventHandler(textBox_TextChanged);
 30InBlock.gif            this.textBoxAddress.TextChanged+=new EventHandler(textBox_TextChanged);
 31InBlock.gif            this.textBoxAge.TextChanged += new EventHandler(textBox_TextChanged);
 32ExpandedSubBlockEnd.gif        }

 33InBlock.gif
 34InBlock.gif        private void buttonOK_Click(object sender, EventArgs e)
 35ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 36InBlock.gif            //No testing for invalid values are made ,as that should not be necessary
 37InBlock.gif            string output;
 38InBlock.gif            
 39InBlock.gif            //Concatenate the text values of for TextBoxes.
 40InBlock.gif            output = "Name:" + this.textBoxName.Text + "\r\n";
 41InBlock.gif            output += "Address:" + this.textBoxAddress.Text + "\r\n";
 42InBlock.gif            output += "Occupation:" + (string)(this.checkBoxProgrammer.Checked ?
 43InBlock.gif                "Programmer" : "Not a programmer"+ "\r\n";    //此句等价于下面这句
 44InBlock.gif            output += "Occupation:" + (string)(this.checkBoxProgrammer.Checked ?
 45InBlock.gif                this.checkBoxProgrammer.Text : ("Not a "+this.checkBoxProgrammer.Text)) + "\r\n";
 46InBlock.gif            output += "Sex:" + (string)(this.radioButtonFemale.Checked ?
 47InBlock.gif                "Female" : "Male"+ "\r\n";    //此句等价于下面这句
 48InBlock.gif            output += "Sex:" + (string)(this.radioButtonFemale.Checked ?
 49InBlock.gif                this.radioButtonFemale.Text : this.radioButtonMale.Text) + "\r\n";
 50InBlock.gif            output += "Age:" + this.textBoxAge.Text;
 51InBlock.gif 
 52InBlock.gif            //Insert the new text.
 53InBlock.gif            this.textBoxOutput.Text = output;
 54ExpandedSubBlockEnd.gif        }

 55InBlock.gif
 56InBlock.gif        private void buttonHelp_Click(object sender, EventArgs e)
 57ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 58InBlock.gif            //Write a short description of each TextBox in the Output TextBox.
 59InBlock.gif            string output;
 60InBlock.gif
 61InBlock.gif            output = "Name=Your name\r\n";
 62InBlock.gif            output += "Address=Your address\r\n";
 63InBlock.gif            output += "Programmer=Check 'Programmer' if you are a programmer\r\n";
 64InBlock.gif            output += "Sex=Choose your sex\r\n";
 65InBlock.gif            output += "Age=Your age";
 66InBlock.gif
 67InBlock.gif            //Insert the new text.
 68InBlock.gif            this.textBoxOutput.Text = output;
 69ExpandedSubBlockEnd.gif        }

 70InBlock.gif
 71InBlock.gif        private void textBoxEmpty_Validating(object sender, CancelEventArgs e)
 72ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 73InBlock.gif            //我们知道这个sender是一个对话框,所以我们将他们强制转换为TextBox
 74InBlock.gif            TextBox tb = (TextBox)sender;
 75InBlock.gif
 76InBlock.gif            //如果对话框是空的话我们设置TextBox背景色为红色来象征问题。
 77InBlock.gif            //如果控件有valid信息,我们就使用控件的Tag值来指出。
 78InBlock.gif            if (tb.Text.Length == 0)
 79ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 80InBlock.gif                tb.BackColor = Color.Red;
 81InBlock.gif                tb.Tag = false;
 82InBlock.gif                //在这个例子中我们不想取消further processing
 83InBlock.gif                //但是如果我们想要这么做的话,我们只需要添加以下一行:
 84InBlock.gif                //e.Cancel=true;
 85ExpandedSubBlockEnd.gif            }

 86InBlock.gif            else
 87ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 88InBlock.gif                this.BackColor = SystemColors.Window;
 89InBlock.gif                tb.Tag = true;
 90ExpandedSubBlockEnd.gif            }

 91InBlock.gif            //Finally ,we call ValidateOK which will set the value of the OK button.
 92InBlock.gif            ValidateOK();
 93ExpandedSubBlockEnd.gif        }

 94InBlock.gif
 95InBlock.gif        private void textBoxAge_KeyPress(object sender, KeyPressEventArgs e)
 96ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 97InBlock.gif            if ((e.KeyChar < 48 || e.KeyChar > 57&& e.KeyChar != 8)
 98ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 99InBlock.gif                e.Handled = true;   //Remove the character
100InBlock.gif                //等于true告诉用户不应该对字符进行任何操作
101ExpandedSubBlockEnd.gif            }

102ExpandedSubBlockEnd.gif        }

103InBlock.gif
104InBlock.gif        private void textBox_TextChanged(object sender, EventArgs e)
105ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
106InBlock.gif            //Cast the sender object to a TextBox
107InBlock.gif            TextBox tb = (TextBox)sender;
108InBlock.gif
109InBlock.gif            //Test if the data is valid and set the tag and back ground color accordingly.
110InBlock.gif            if (tb.Text.Length == 0)
111ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
112InBlock.gif                tb.Tag = false;
113InBlock.gif                tb.BackColor = Color.Red;
114ExpandedSubBlockEnd.gif            }

115InBlock.gif            else
116ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
117InBlock.gif                tb.Tag = true;
118InBlock.gif                tb.BackColor = SystemColors.Window;
119ExpandedSubBlockEnd.gif            }

120InBlock.gif
121InBlock.gif            //Call ValidateOK to set the OK button
122InBlock.gif            ValidateOK();
123ExpandedSubBlockEnd.gif        }

124InBlock.gif
125InBlock.gif        private void ValidateOK()
126ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif
127InBlock.gif            //Set the OK button to enabled if all the Tags are true
128InBlock.gif            this.buttonOK.Enabled = ((bool)(this.textBoxName.Tag) &&
129InBlock.gif                (bool)(this.textBoxAge.Tag) &&
130InBlock.gif                (bool)(this.textBoxAddress.Tag));
131ExpandedSubBlockEnd.gif        }

132ExpandedSubBlockEnd.gif    }

133ExpandedBlockEnd.gif}

[示例说明]:
1、开发语言:C#
2、开发环境:Visual Studio.Net 2005 Team suite
3、开发模板:C#.net项目->Windows应用程序

转载于:https://www.cnblogs.com/volnet/archive/2006/11/27/574437.html

编程实例 MICROSOFT SOFTWARE LICENSE TERMS Microsoft Visual Studio 2005 and .NET Framework 2.0 Samples These license terms are an agreement between Microsoft Corporation (or based on where you live, one of its affiliates) and you. Please read them. They apply to the software named above, which includes the media on which you received it, if any. The terms also apply to any Microsoft * updates, * supplements, * Internet-based services, and * support services for this software, unless other terms accompany those items. If so, those terms apply. BY USING THE SOFTWARE, YOU ACCEPT THESE TERMS. IF YOU DO NOT ACCEPT THEM, DO NOT USE THE SOFTWARE. If you comply with these license terms, you have the rights below. 1. INSTALLATION AND USE RIGHTS. You may install and use any number of copies of the software on your devices. 2. ADDITIONAL LICENSING REQUIREMENTS AND/OR USE RIGHTS. a. Distributable Code. The software contains code that you are permitted to distribute in programs you develop if you comply with the terms below. i. Right to Use and Distribute. The code and text files listed below are 揇istributable Code.? * Sample Code. You may modify, copy, and distribute the source and object code form of the sample source code included in the subfolders of the project files. * Third Party Distribution. You may permit distributors of your programs to copy and distribute the Distributable Code as part of those programs. ii. Distribution Requirements. For any Distributable Code you distribute, you must * add significant primary functionality to it in your programs; * require distributors and external end users to agree to terms that protect it at least as much as this agreement; * display your valid copyright notice on your programs; and * indemnify, defend, and hold harmless Microsoft from any claims, including attorneys?fees, related to the distribution or use of your programs. iii. Distribution Restrictions. You may not * alter any copyright, trademark or patent notice in the Distributable Code; * use Microsoft抯 trademarks in your programs?names or in a way that suggests your programs come from or are endorsed by Microsoft; * distribute Distributable Code to run on a platform other than the Windows platform; * include Distributable Code in malicious, deceptive or unlawful programs; or * modify or distribute the source code of any Distributable Code so that any part of it becomes subject to an Excluded License. An Excluded License is one that requires, as a condition of use, modification or distribution, that * the code be disclosed or distributed in source code form; or * others have the right to modify it. 3. SCOPE OF LICENSE. The software is licensed, not sold. This agreement only gives you some rights to use the software. Microsoft reserves all other rights. Unless applicable law gives you more rights despite this limitation, you may use the software only as expressly permitted in this agreement. In doing so, you must comply with any technical limitations in the software that only allow you to use it in certain ways. You may not * work around any technical limitations in the software; * reverse engineer, decompile or disassemble the software, except and only to the extent that applicable law expressly permits, despite this limitation; * make more copies of the software than specified in this agreement or allowed by applicable law, despite this limitation; * publish the software for others to copy; * rent, lease or lend the software; * transfer the software or this agreement to any third party; or * use the software for commercial software hosting services. 4. BACKUP COPY. You may make one backup copy of the software. You may use it only to reinstall the software. 5. DOCUMENTATION. Any person that has valid access to your computer or internal network may copy and use the documentation for your internal, reference purposes. 6. EXPORT RESTRICTIONS. The software is subject to United States export laws and regulations. You must comply with all domestic and international export laws and regulations that apply to the software. These laws include restrictions on destinations, end users and end use. For additional information, see www.microsoft.com/exporting. 7. SUPPORT SERVICES. Because this software is 揳s is,?we may not provide support services for it. 8. ENTIRE AGREEMENT. This agreement, and the terms for supplements, updates, Internet-based services and support services that you use, are the entire agreement for the software and support services. 9. APPLICABLE LAW. a. United States. If you acquired the software in the United States, Washington state law governs the interpretation of this agreement and applies to claims for breach of it, regardless of conflict of laws principles. The laws of the state where you live govern all other claims, including claims under state consumer protection laws, unfair competition laws, and in tort. b. Outside the United States. If you acquired the software in any other country, the laws of that country apply. 10. LEGAL EFFECT. This agreement describes certain legal rights. You may have other rights under the laws of your country. You may also have rights with respect to the party from whom you acquired the software. This agreement does not change your rights under the laws of your country if the laws of your country do not permit it to do so. 11. DISCLAIMER OF WARRANTY. THE SOFTWARE IS LICENSED 揂S-IS.? YOU BEAR THE RISK OF USING IT. MICROSOFT GIVES NO EXPRESS WARRANTIES, GUARANTEES OR CONDITIONS. YOU MAY HAVE ADDITIONAL CONSUMER RIGHTS UNDER YOUR LOCAL LAWS WHICH THIS AGREEMENT CANNOT CHANGE. TO THE EXTENT PERMITTED UNDER YOUR LOCAL LAWS, MICROSOFT EXCLUDES THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 12. LIMITATION ON AND EXCLUSION OF REMEDIES AND DAMAGES. YOU CAN RECOVER FROM MICROSOFT AND ITS SUPPLIERS ONLY DIRECT DAMAGES UP TO U.S. $5.00. YOU CANNOT RECOVER ANY OTHER DAMAGES, INCLUDING CONSEQUENTIAL, LOST PROFITS, SPECIAL, INDIRECT OR INCIDENTAL DAMAGES. This limitation applies to * anything related to the software, services, content (including code) on third party Internet sites, or third party programs; and * claims for breach of contract, breach of warranty, guarantee or condition, strict liability, negligence, or other tort to the extent permitted by applicable law. It also applies even if Microsoft knew or should have known about the possibility of the damages. The above limitation or exclusion may not apply to you because your country may not allow the exclusion or limitation of incidental, consequential or other damages. Please note: As this software is distributed in Quebec, Canada, some of the clauses in this agreement are provided below in French. Remarque : Ce logiciel 閠ant distribu?au Qu閎ec, Canada, certaines des clauses dans ce contrat sont fournies ci-dessous en fran鏰is. EXON蒖ATION DE GARANTIE. Le logiciel vis?par une licence est offert ?tel quel ? Toute utilisation de ce logiciel est ?votre seule risque et p閞il. Microsoft n抋ccorde aucune autre garantie expresse. Vous pouvez b閚閒icier de droits additionnels en vertu du droit local sur la protection dues consommateurs, que ce contrat ne peut modifier. La ou elles sont permises par le droit locale, les garanties implicites de qualit?marchande, d抋d閝uation ?un usage particulier et d抋bsence de contrefa鏾n sont exclues. LIMITATION DES DOMMAGES-INT蒖蔜S ET EXCLUSION DE RESPONSABILIT?POUR LES DOMMAGES. Vous pouvez obtenir de Microsoft et de ses fournisseurs une indemnisation en cas de dommages directs uniquement ?hauteur de 5,00 $ US. Vous ne pouvez pr閠endre ?aucune indemnisation pour les autres dommages, y compris les dommages sp閏iaux, indirects ou accessoires et pertes de b閚閒ices. Cette limitation concerne : * tout ce qui est reli?au logiciel, aux services ou au contenu (y compris le code) figurant sur des sites Internet tiers ou dans des programmes tiers ; et * les r閏lamations au titre de violation de contrat ou de garantie, ou au titre de responsabilit?stricte, de n間ligence ou d抲ne autre faute dans la limite autoris閑 par la loi en vigueur. Elle s抋pplique 間alement, m阭e si Microsoft connaissait ou devrait conna顃re l掗ventualit?d抲n tel dommage. Si votre pays n抋utorise pas l抏xclusion ou la limitation de responsabilit?pour les dommages indirects, accessoires ou de quelque nature que ce soit, il se peut que la limitation ou l抏xclusion ci-dessus ne s抋ppliquera pas ?votre 間ard. EFFET JURIDIQUE. Le pr閟ent contrat d閏rit certains droits juridiques. Vous pourriez avoir d抋utres droits pr関us par les lois de votre pays. Le pr閟ent contrat ne modifie pas les droits que vous conf鑢ent les lois de votre pays si celles ci ne le permettent pas.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值