What is the best possible way to enable the visibility of a label inside a form.
If you see the code below .
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;
}
Why does that label doesn't show up? But if try to make a messagebox . a messagebox pops up.
You are checking the value of txtboxTwo
in the TextChanged
event of txtboxOne
.
That is why messagebox
block works and the later block does not.
Change it to:
private void txtboxOne_TextChanged(object sender, EventArgs e)
{
if (txtboxOne.Text == "x")
{
lblgrpTwoSecond.Visible = true;
}
}
if you indeed want to check txtboxTwo.Text dont use else if, use 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;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.