posted @ 2007-03-18 20:34 dn 阅读(80) 评论(0) 编辑
对教材2.6.2、2.6.3、2.6.4部分进行的例题演示,代码如下:
 1//对控件验证事件的处理
 2        private void minValueTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e)
 3        {
 4            if(Convert.ToInt32(minValueTextBox.Text) >= Convert.ToInt32(maxValueTextBox.Text))
 5            {
 6                e.Cancel = true;
 7                MessageBox.Show("You must enter a minimum value that is less than the Maximum value");
 8            }

 9        }

10
11//利用ErrorProvider控件完成验证
12        private void textBox1_Validating(object sender, System.ComponentModel.CancelEventArgs e)
13        {
14            try
15            {
16                int x= Int32.Parse(textBox1.Text);
17                errorProvider1.SetError(textBox1,"");
18            }

19            catch
20            {
21                errorProvider1.SetError(textBox1,"Not a integer value.");
22            }

23        }

 

 1//窗体级别的验证
 2        private void btnValidate_Click(object sender, System.EventArgs e)
 3        {
 4            foreach(System.Windows.Forms.Control aControl in this.Controls)
 5            {
 6                if(aControl is System.Windows.Forms.TextBox && aControl.Text=="")
 7                {
 8                    aControl.Focus();
 9                    return;
10                }

11            }

12            MessageBox.Show("通过了验证!");
13
14        }

完整例题代码下载:Validating.rar
posted @ 2007-03-18 20:21 dn 阅读(64) 评论(0) 编辑
对教材2.4.2部分进行的演示,相关代码如下:
 1private void button1_Click(object sender, System.EventArgs e)
 2        {
 3            //创建控件实例
 4            CheckBox signatureCheckBox = new CheckBox();
 5            signatureCheckBox.Name = "myCheckBox";
 6            signatureCheckBox.Text = "Signature required";
 7            signatureCheckBox.Width = 224;
 8            signatureCheckBox.Left = 24;
 9            signatureCheckBox.Top = 80;
10
11            //将控件添加到窗体中的GroupBox控件实例中
12            groupBox1.Controls.Add(signatureCheckBox);
13        }

完整源代码下载:runtime_control.rar
posted @ 2007-03-18 20:14 dn 阅读(74) 评论(0) 编辑