我正在尝试使用TabControl创建一个使用MDI的应用程序。当frmMain创建一个新的frmCharacter时,如果有多个,则将它们添加到TabControl。
问题是,对一个表单中的ComboBox,Control进行的更改会更改其他复制表单中的相同Control。
有人可以帮我解决这个问题吗?
谢谢。
frmMain
namespace DarkHeresyCC
{
public partial class frmMain : Form
{
public frmMain()
{
InitializeComponent();
}
private void newCharacterToolStripMenuItem_Click(object sender, EventArgs e)
{
Character objCharacter = new Character();
frmCharacter frmChar = new frmCharacter(objCharacter);
frmChar.MdiParent = this;
frmChar.WindowState = FormWindowState.Maximized;
frmChar.Show();
}
private void frmMain_MdiChildActivate(object sender, EventArgs e)
{
// If there are no child forms, hide the tab control.
if (this.ActiveMdiChild == null)
tabMain.Visible = false;
else
{
this.ActiveMdiChild.WindowState = FormWindowState.Maximized;
// If this is a new child form and does not have a tab page, create one.
if (this.ActiveMdiChild.Tag == null)
{
// Add a tab page.
TabPage tp = new TabPage(this.ActiveMdiChild.Text);
tp.Tag = this.ActiveMdiChild;
tp.Parent = tabMain;
//if (this.ActiveMdiChild.GetType() == typeof(frmCareer))
//{
// tp.Text = ((frmCareer)this.ActiveMdiChild).CharacterName;
//}
tabMain.SelectedTab = tp;
this.ActiveMdiChild.Tag = tp;
this.ActiveMdiChild.FormClosed += ActiveMdiChild_FormClosed;
}
// Don't show the tab control if there is only one window open.
if (tabMain.TabCount <= 1)
tabMain.Visible = false;
else
tabMain.Visible = true;
}
}
private void ActiveMdiChild_FormClosed(object sender, FormClosedEventArgs e)
{
(sender as Form).FormClosed -= ActiveMdiChild_FormClosed;
(sender as Form).Dispose();
((sender as Form).Tag as TabPage).Dispose();
GC.Collect();
// Don't show the tab control if there is only one window open.
if (tabMain.TabCount <= 1)
tabMain.Visible = false;
}
private void tabMain_SelectedIndexChanged(object sender, EventArgs e)
{
if (tabMain.SelectedTab != null && tabMain.SelectedTab.Tag != null)
(tabMain.SelectedTab.Tag as Form).Select();
}
private void closeAllToolStripMenuItem_Click(object sender, EventArgs e)
{
foreach (Form childForm in MdiChildren)
{
childForm.Close();
}
}
}
}
frmCharacter
namespace DarkHeresyCC
{
public partial class frmCharacter : Form
{
private Character _objCharacter;
public frmCharacter(Character objCharacter)
{
_objCharacter = objCharacter;
InitializeComponent();
}
}
}