父窗体代码:
//dockPanel1为DockPanel的实例 FrmOption frmOption = new FrmOption(dockPanel1); frmOption.Show(dockPanel1);
子窗体代码:
public partial class FrmOption : DockContent { private readonly DockPanel dockPanel1 = new DockPanel(); public FrmOption(DockPanel dockPanel1) { InitializeComponent(); this.dockPanel1 = dockPanel1; } private void FrmOption_Load(object sender, EventArgs e) { //调用父窗体的ToolStripProgressBar ,在父窗体ToolStripProgressBar
必须设置为Modifier=Internal以上级别 ToolStripProgressBar toolStripProgressBar = ((MainForm)MdiParent).toolStripProgressBar; toolStripProgressBar.Visible = true; toolStripProgressBar.Value = 90; } private void button1_Click(object sender, EventArgs e) { MainForm mainForm = MdiParent as MainForm; foreach (Form child in mainForm.MdiChildren) { //此处将在父窗体选项卡上显示 if (child.Name == "FrmDepartment") { child.Activate(); return; } } FrmDepartment frm = new FrmDepartment(); frm.Show(dockPanel1); } }