C#textbox显示问题 怎么使程序运行后Textbox里显示值,比如,运行后要使Textbox里显示1≤key≤4,并且鼠标单击后就没显示了,而你输入的值只能在这范围之内,各位大虾们,帮帮忙哈,谢谢咯 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用textBox1_TextChanged判断下好了 随便参考下吧!可能有问题哦!写的也不好!private void Form1_Load(object sender, EventArgs e) { this.textBox1.Text = "1<=key<=4"; this.textBox1.Click += new EventHandler(textBox1_Click); } void textBox1_Click(object sender, EventArgs e) { this.textBox1.Text = null; this.textBox1.TextChanged += new EventHandler(textBox1_TextChanged); } void textBox1_TextChanged(object sender, EventArgs e) { int s = int.Parse(this.textBox1.Text); { if (s >4||s < 0) { if (MessageBox.Show("输入内容不正确,选择“是”请重新输入", "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { this.textBox1.Text = "1" } } } } private void Form1_Load(object sender, EventArgs e) { this.textBox1.Text = "1 <=key <=4"; this.textBox1.Click += new EventHandler(textBox1_Click); } void textBox1_Click(object sender, EventArgs e) { this.textBox1.Text = null; this.textBox1.TextChanged += new EventHandler(textBox1_TextChanged); } void textBox1_TextChanged(object sender, EventArgs e) { int s = int.Parse(this.textBox1.Text); if (s >4||s < 0) { if (MessageBox.Show("输入内容不正确,选择“是”请重新输入", "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { this.textBox1.Text = "1"; } } } 设置步骤:1: textbox的Maxlength属性=1 textbox的text属性="1≤key≤4"2:textBox_Enter的事件中写如下代码: this.textBox2.Text = "";3: private void textBox_KeyPress(object sender, KeyPressEventArgs e) { if ((e.KeyChar < 48 || e.KeyChar > 53)&& e.KeyChar != 8 && e.KeyChar != 46) { e.Handled = true; } } 设置步骤: 1:textbox 的maxlength属性:1 textbox 的text属性:1≤key≤4 2:private void textBox_Enter(object sender, EventArgs e) { this.textBox2.Text = ""; }3:private void textBox_KeyPress(object sender, KeyPressEventArgs e) { this.textBox.Text = ""; if ((e.KeyChar < 48 || e.KeyChar > 53) && e.KeyChar != 8 && e.KeyChar != 46) { e.Handled = true; } } 如何让WINDOWS服务启动程序到当前用户界面 请问C#能写浏览器插件吗?BHO这种 用C#查找矩阵的INDEX 如何获取groupbox里面textbox在窗体from的坐标? tabcontrol的问题 更新完如注册表中的系统变量这样的字符串后,如何立即生效? c# socket 菜问题 oracle数据库(查询) 如何安装Devexress的ASP.NET插件? 进程输出如何实时显示在textbox里? C# 中如何弹出覆盖文件的确认对话框? 类型转换问题,谢谢
{
this.textBox1.Text = "1<=key<=4";
this.textBox1.Click += new EventHandler(textBox1_Click);
} void textBox1_Click(object sender, EventArgs e)
{
this.textBox1.Text = null;
this.textBox1.TextChanged += new EventHandler(textBox1_TextChanged);
}
void textBox1_TextChanged(object sender, EventArgs e)
{
int s = int.Parse(this.textBox1.Text);
{
if (s >4||s < 0)
{
if (MessageBox.Show("输入内容不正确,选择“是”请重新输入", "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
this.textBox1.Text = "1" }
}
}
}
{
this.textBox1.Text = "1 <=key <=4";
this.textBox1.Click += new EventHandler(textBox1_Click);
} void textBox1_Click(object sender, EventArgs e)
{
this.textBox1.Text = null;
this.textBox1.TextChanged += new EventHandler(textBox1_TextChanged);
}
void textBox1_TextChanged(object sender, EventArgs e)
{
int s = int.Parse(this.textBox1.Text);
if (s >4||s < 0)
{
if (MessageBox.Show("输入内容不正确,选择“是”请重新输入", "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
this.textBox1.Text = "1"; }
}
}
1:
textbox的Maxlength属性=1
textbox的text属性="1≤key≤4"
2:textBox_Enter的事件中写如下代码:
this.textBox2.Text = "";
3:
private void textBox_KeyPress(object sender, KeyPressEventArgs e)
{
if ((e.KeyChar < 48 || e.KeyChar > 53)&& e.KeyChar != 8 && e.KeyChar != 46)
{
e.Handled = true;
}
}
1:textbox 的maxlength属性:1
textbox 的text属性:1≤key≤4 2:private void textBox_Enter(object sender, EventArgs e)
{
this.textBox2.Text = ""; }
3:private void textBox_KeyPress(object sender, KeyPressEventArgs e)
{
this.textBox.Text = "";
if ((e.KeyChar < 48 || e.KeyChar > 53) && e.KeyChar != 8 && e.KeyChar != 46)
{
e.Handled = true;
}
}