在父表单中启动子表单后,父表单中标签的透明度消失(变为灰色)

时间:2018-12-20 10:58:14

标签: c#

Menu form (parent form) randomFacts form (child form)

菜单窗体是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;
    }

Appearance of labels in menu form if I load randomFacts form first

如有必要,我将提供更多代码。我该如何解决?

0 个答案:

没有答案