0

我试图用另一个表单创建一个表单实例,然后将该表单添加到主表单中。但我添加的表格没有显示。我想在所有控件顶部的中心显示该表单。

这是我的代码

BBA.Controls.ExecludeSpecialist ucExecludeSpecialist = null;
Form frmContainer = null;

private void btnExclude_Click(object sender, EventArgs e)
{
    if (ucExecludeSpecialist != null)
    {
        if (frmContainer != null)
        {
            frmContainer.Controls.Remove(ucExecludeSpecialist);
            ucExecludeSpecialist = null;
        }
    }

    if (frmContainer != null)
    {
        this.Controls.Remove(frmContainer);
        frmContainer = null;
    }

    frmContainer = new Form();
    frmContainer.ControlBox = false;
    frmContainer.StartPosition = FormStartPosition.Manual;
    frmContainer.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;

    ucExecludeSpecialist = new BBA.Controls.ExecludeSpecialist();
    ucExecludeSpecialist.SaveClicked += 
        new BBA.Controls.ExecludeSpecialist.SaveComplete(OnSaveClicked);
    ucExecludeSpecialist.CloseClicked += 
        new BBA.Controls.ExecludeSpecialist.CloseComplete(OnCloseClicked);
    ucExecludeSpecialist.BringToFront();
    frmContainer.Height = ucExecludeSpecialist.Height;
    frmContainer.Width = ucExecludeSpecialist.Width;
    //frmContainer.Top = this.Height - frmContainer.Height / 2;
    //frmContainer.Left = this.Height - frmContainer.Height / 2;
    frmContainer.BringToFront();
    frmContainer.TopLevel = false;
    frmContainer.Controls.Add(ucExecludeSpecialist);
    this.Controls.Add(frmContainer);
}

请指导我如何在中心的另一个表单的所有控件之上显示该表单。谢谢

4

1 回答 1

1

如果我理解您的评论正确,您的问题是 DataGrid 覆盖了您最近添加的表单?尝试 :

添加后

frmContainer.Show();

你的表格应该是可见的。之后你应该解决你的问题,如果你打电话ucExecludeSpecialist.BringToFront(); 打电话frmContainer.Show();

例子 :

    private void button1_Click(object sender, EventArgs e)
    {

        frmContainer = new Form();
        frmContainer.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;

        frmContainer.Height = this.Height / 2;
        frmContainer.Width = this.Width / 2;
        frmContainer.BackColor = Color.Red;
        frmContainer.TopLevel = false;
        this.Controls.Add(frmContainer);
        frmContainer.Show();
        frmContainer.BringToFront();
    }
于 2013-01-22T12:04:39.023 回答