![](/img/trans.png)
[英]Manipulate a list within textbox textchange event in C# desktop application
[英]C# Textbox textchange property event
什么是启用表单内标签可见性的最佳方法。
如果你看到下面的代码。
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
lblgrpTwoFirst.Visible = false;
lblgrpTwoSecond.Visible = false;
lblgrpTwoThird.Visible = false;
lblgrpTwoFourt.Visible = false;
}
private void txtboxOne_TextChanged(object sender, EventArgs e)
{
if (txtboxOne.Text == "z")
{
MessageBox.Show("The Goose Eat the Beans");
}
else if (txtboxTwo.Text == "x")
{
lblgrpTwoSecond.Visible = true;
}
为什么这个标签没有出现? 但如果试图制作一个消息框。 弹出一个消息框。
您正在检查txtboxTwo
的TextChanged
事件中txtboxOne
。
这就是messagebox
块工作的原因,后面的块没有。
将其更改为:
private void txtboxOne_TextChanged(object sender, EventArgs e)
{
if (txtboxOne.Text == "x")
{
lblgrpTwoSecond.Visible = true;
}
}
如果你确实想检查txtboxTwo.Text不要使用else if,请使用if:
private void txtboxOne_TextChanged(object sender, EventArgs e)
{
if (txtboxOne.Text == "z")
{
MessageBox.Show("The Goose Eat the Beans");
}
if (txtboxTwo.Text == "x")
{
lblgrpTwoSecond.Visible = true;
}
}
检查你的条件
lblgrpTwoSecond.Visible = txtboxTwo.Text == "x" ? true : false;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.