标题:[求助]赋值问题
只看楼主
触电
Rank: 1
等 级:新手上路
威 望:1
帖 子:228
专家分:0
注 册:2006-7-26
 问题点数:0 回复次数:9 
[求助]赋值问题

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Ch14TextBoxTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();

this.buttonOK.Enabled = false;
this.textBoxAddress.Tag = false;
this.textBoxAge.Tag = false;
this.textBoxName.Tag = false;
this.textBoxOccupation.Tag = false;

this.textBoxName.Validating += new
System.ComponentModel.CancelEventHandler(this.textBoxEmpty_Validating); //委托能够赋值给属性?这句话究竟是什么意思?

this.textBoxAddress.Validating += new
System.ComponentModel.CancelEventHandler(this.textBoxEmpty_Validating);

this.textBoxOccupation.Validating+=new
System.ComponentModel.CancelEventHandler(this.textBoxOccupation_Validating);

this.textBoxAge.Validating+=new
System.ComponentModel.CancelEventHandler(this.textBoxEmpty_Validating);

this.textBoxName.TextChanged += new
System.EventHandler(this.textBox_TextChanged);
this.textBoxAddress.TextChanged+=new
System.EventHandler(this.textBox_TextChanged);
this.textBoxAge.TextChanged+=new
System.EventHandler(this.textBox_TextChanged);
this.textBoxOccupation.TextChanged+=new
System.EventHandler(this.textBox_TextChanged);

}

private void button1_Click(object sender, EventArgs e)
{
string output;

output = "Name: " + this.textBoxName.Text + "\r\n";
output += "Address: " + this.textBoxAddress.Text + "\r\n";
output += "Occupation: " + this.textBoxOccupation.Text + "\r\n";
output += "Age: " + this.textBoxAge.Text + "\r\n";

this.textBoxOutput.Text = output;
}

private void button2_Click(object sender, EventArgs e)
{
string output;

output = "Name=Your name\r\n";
output += "Address=Your address\r\n";
output += "Occupation=Only allowed value is 'Programmer'\r\n";

this.textBoxOutput.Text = output;
}

private void textBoxEmpty_Validating(object sender, System.ComponentModel.CancelEventArgs e)
{
TextBox tb = (TextBox)sender;

if (tb.Text.Length == 0)
{
tb.BackColor = Color.Red;
tb.Tag = false;
}

else
{
tb.BackColor = System.Drawing.SystemColors.Window;
tb.Tag = true;
}

ValidateOK();

}

private void textBoxOccupation_Validating(object sender, System.ComponentModel.CancelEventArgs e)
{
TextBox tb = (TextBox)sender;

if (tb.Text.CompareTo("Programmer") == 0 || tb.Text.Length == 0)
{
tb.Tag = true;
tb.BackColor = System.Drawing.SystemColors.Window;
}

else
{
tb.Tag = false;
tb.BackColor = Color.Red;
}

ValidateOK();
}

private void textBoxAge_KeyPress(object sender, KeyPressEventArgs e)
{
if ((e.KeyChar < 48 || e.KeyChar > 57) && e.KeyChar != 8)
e.Handled = true;
}

private void textBox_TextChanged(object sender, System.EventArgs e)
{
TextBox tb = (TextBox)sender;

if (tb.Text.Length == 0 && tb != textBoxOccupation)
{
tb.Tag = false;
tb.BackColor = Color.Red;
}

else if (tb == textBoxOccupation && (tb.Text.Length != 0 && tb.Text.CompareTo("Programmer") != 0))
{
tb.Tag = false;
}

else
{
tb.Tag = true;
tb.BackColor = SystemColors.Window;
}

ValidateOK();
}

private void ValidateOK()
{
this.buttonOK.Enabled=((bool)(this.textBoxAddress.Tag)&&
(bool)(this.textBoxAge.Tag)&&
(bool)(this.textBoxName.Tag)&&
(bool)(this.textBoxOccupation.Tag));
}

private void Form1_Load(object sender, EventArgs e)
{

}


}
}

搜索更多相关主题的帖子: using 赋值 System false Tag 
2006-11-06 20:03
bygg
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:乖乖的心中
等 级:版主
威 望:241
帖 子:13555
专家分:3076
注 册:2006-10-23
得分:0 
this.textBoxName.Validating += new
System.ComponentModel.CancelEventHandler(this.textBoxEmpty_Validating);


委托。
textBoxName.Validating 的方法和textBox.Empty_Validating的一样。

飘过~~
2006-11-06 20:12
触电
Rank: 1
等 级:新手上路
威 望:1
帖 子:228
专家分:0
注 册:2006-7-26
得分:0 
那这句话该怎样来理解呢?
2006-11-06 20:15
触电
Rank: 1
等 级:新手上路
威 望:1
帖 子:228
专家分:0
注 册:2006-7-26
得分:0 
左边是事件..右边是委托..不太懂了
2006-11-06 21:36
joerson
Rank: 1
等 级:新手上路
帖 子:27
专家分:0
注 册:2006-10-15
得分:0 

关于这个程序我也有个问题,就是在运行以上程序时候出现错误:
Form1.Designer.cs

namespace WindowsApplication8
{
partial class Form1
{
private System.ComponentModel.IContainer components = null;

/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing) //错误提示为:WindowsAppliction.Form1.Dispose(bool):没有找到合适的方法重写
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

#region Windows 窗体设计器生成的代码

private void InitializeComponent()
{
this.SuspendLayout();

this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(292, 266);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);

}

#endregion
}
}
哪位大大帮忙看看是怎么回事,我装的是VS2005 ,好象是实验版..是不是这方面出的问题`?

[此贴子已经被作者于2006-11-7 2:25:02编辑过]

2006-11-07 02:23
jingzhao22visa
Rank: 1
等 级:新手上路
威 望:1
帖 子:343
专家分:0
注 册:2006-8-10
得分:0 
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
你看看program里面有没有这个函数?


2006-11-07 11:32
触电
Rank: 1
等 级:新手上路
威 望:1
帖 子:228
专家分:0
注 册:2006-7-26
得分:0 
自动生成的时候应该是没有这个函数的
2006-11-07 12:17
触电
Rank: 1
等 级:新手上路
威 望:1
帖 子:228
专家分:0
注 册:2006-7-26
得分:0 
JINGZHAO同学..能不能回答我在上面所提的问题呢?
2006-11-07 12:18
chenjin145
Rank: 1
等 级:禁止访问
帖 子:3922
专家分:0
注 册:2006-7-12
得分:0 
触电: 把textBoxEmpty_Validating委託到事件中


joerson: 你根本沒有父類 何來的override

[url=javascript:alert(1);] [div]fdgfdgfdg\" on\"[/div] [/url]
2006-11-07 12:42
触电
Rank: 1
等 级:新手上路
威 望:1
帖 子:228
专家分:0
注 册:2006-7-26
得分:0 
thanks....
2006-11-09 22:03



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-101149-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.037426 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved