菜单窗体是randomFacts窗体(子窗体)的Mdi父窗体。
每当我单击菜单窗体上的测验按钮时,就会执行以下代码(项目最初隐藏在菜单窗体上,但是在单击测验按钮时会显示出来):
private void btn1Quiz_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Start quiz?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
foreach (Form f in OwnedForms)
{
f.Hide();
}
randomFacts.Hide();
randomFacts.Refresh();
ShowAll(); // shows quiz items
SetTransparency();
}
}
private void ShowAll()
{
labelQuestion.Show();
labelQuestionNumber.Show();
labelScore.Show();
labelScore.Text = "Score: 0";
labelTheme.Show();
btnOption1.Show();
btnOption2.Show();
btnOption3.Show();
btnOption4.Show();
pictureBox1.Show();
SetTransparency();
Image background = new Bitmap("andromeda.jpg");
this.BackgroundImage = null;
this.BackgroundImage = background;
}
private void SetTransparency()
{
labelQuestion.BackColor = Color.Transparent;
labelTheme.BackColor = Color.Transparent;
labelQuestionNumber.BackColor = Color.Transparent;
labelScore.BackColor = Color.Transparent;
}
但是,如果在加载菜单表单时首先单击“事实”按钮,并执行以下代码,然后单击“测验”按钮以加载测验项目,则测验标签将失去透明性,并且背景为灰色
private void btn2Facts_Click(object sender, EventArgs e)
{
// menu form is a parent, randomFacts is a child.
this.IsMdiContainer = true;
randomFacts.MdiParent = this;
HideAll();
randomFacts.Show();
randomFacts.Location = new Point(200, 10);
randomFacts.FormBorderStyle = FormBorderStyle.None;
}
如有必要,我将提供更多代码。我该如何解决?