我加了一个textbox和两个button,在一个button里给textbox赋值,另一个判断代码如下:
namespace shiyan
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void textBox1_TextChanged(object sender, EventArgs e)
{ } private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = null;
} private void button2_Click(object sender, EventArgs e)
{
if (textBox1.Text == null)
MessageBox.Show("T");
}
}
}运行后依次点击button1和button2,没有任何结果。如果在button赋值任意一个其他的,再在button2做相应的变动后,运行后就会弹出“T”的文本。大家说说这是,为什么啊,我刚学的c#,大家多多指教。
namespace shiyan
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void textBox1_TextChanged(object sender, EventArgs e)
{ } private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = null;
} private void button2_Click(object sender, EventArgs e)
{
if (textBox1.Text == null)
MessageBox.Show("T");
}
}
}运行后依次点击button1和button2,没有任何结果。如果在button赋值任意一个其他的,再在button2做相应的变动后,运行后就会弹出“T”的文本。大家说说这是,为什么啊,我刚学的c#,大家多多指教。
解决方案 »
- 数据库运算和IIS运算哪个效率高?谢谢!
- 请教在winfrom里面使用FTP上传图片问题
- C#帮小弟介绍基本好书和好的视频讲解,小弟是新手,刚刚开始想学习C#
- 统计信息显示
- C# 字符串数组问题
- 对于object类型,其实际类型可能是Single、Decimal、Double三种,如何将object转为保留2位小数的字符串。
- 请问如何设置属性可以使生成页面时是页面最大化显示?
- 学习c/s开发
- 高手们,为什么MSN用了一阵,不说话,在过一会儿就Downline,需要在连接一次????
- crystal report 8.5 develper edition 与 .net 里带的有什么区别?
- C#调用C++的DLL时 结构体参数问题
- 简单小问题
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = “”;
} private void button2_Click(object sender, EventArgs e)
{
if (textBox1.Text == “”)
MessageBox.Show("T");
}
看看能不能显示T文本
设置成空就可以。别设置为null.
{
textBox1.Text = null;
} private void button2_Click(object sender, EventArgs e)
{
if (textBox1.Text == null)
MessageBox.Show("null");
else if (textBox1.Text == "")
MessageBox.Show("empty");
}
{
textBox1.Text = null;
} private void button2_Click(object sender, EventArgs e)
{
if (textBox1.Text.Equals(""))
MessageBox.Show("T");
}
{
MessageBox.Show("text is null");
}
{
MessageBox.Show("text is null");
}
// 摘要:
// 获取或设置 System.Windows.Forms.TextBox 中的当前文本。
//
// 返回结果:
// 在控件中显示的文本。
public override string Text { get; set; }
估计是判断过的,如果你是null,set里直接付成empty
和null得概念是不同的