如何在其中嵌入的表单关闭时关闭选项卡?

时间:2012-04-03 19:28:56

标签: c# winforms

我的表单已嵌入到标签页的顶部。当我关闭标签页顶部的表格时,如何关闭标签页呢?

我将表单放在标签页上时的代码更像是这样:

client c = new client(car_name, owner);   //here client is another winform class
c.TopLevel = false;
c.Visible = true;
c.BackColor = Color.Ivory;
c.FormBorderStyle = FormBorderStyle.None;
c.Dock = DockStyle.Fill;
tabControl1.TabPages[tab_index].Controls.Add(c);

1 个答案:

答案 0 :(得分:3)

使用FormClosing事件:

private void ClientForm_FormClosing(object sender, FormClosedEventArgs e)
    {
      ((TabControl)((TabPage)this.Parent).Parent).TabPages.Remove((TabPage)this.Parent);
    }