我想在C#WinForms的Strip Menu中显示/隐藏对象。
我尝试了以下操作:
private void button1_Click(object sender, EventArgs e)
{
int preCounter = 0;
int check = 0;
for (int i = 0; i < Word.Text.Length; i++)
{
if (textBoxTab[i].Text == Letter.Text)
{
textBoxTab[i].Visible = true;
fakeBox[i].Visible = false;
}
else preCounter++;
if(textBoxTab[i].Visible == true)
{
check++;
}
}
if(preCounter == Word.Text.Length)
{
counter++; // licznik błędów
label1.Text = counter.ToString(); // zapis błędów
}
Letter.Text = string.Empty;
if(check == Word.Text.Length)
{
MessageBox.Show("YOU WIN!!!");
}
}
有剥离菜单:
private void newGameToolStripMenuItem_Click(object sender, EventArgs e)
{
Word.Visible = true;
WordButton.Visible = true;
Wisielec.Visible = true;
Podaj.Visible = true;
Letter.Visible = false; //cant hide
button1.Visible = false;
label1.Visible = false;
Counter_l.Visible = false;
Podaj2.Visible = false;
for (int i = 0; i < Word.Text.Length; i++) // cant hide
{
textBoxTab[i].Visible = false;
textBoxTab[i].Text = string.Empty;
fakeBox[i].Visible = false;
fakeBox[i].Text = string.Empty;
}
Word.Text = string.Empty;
Letter.Text = string.Empty;
}
如果再次单击菜单栏,则实际上我想看到的对象是可见的,但是有些我想隐藏的对象仍然可见。
private void button1_Click(object sender, EventArgs e)
{
//Your code
//Your code
this.Invalidate(); // perform form re-draw
}
private void newGameToolStripMenuItem_Click(object sender, EventArgs e)
{
//Your code
//Your code
this.Invalidate(); // perform form re-draw
}