C#文本在tabcontrol的tabpage中不会更改
我有一些标签页是打开的,每个标签页都是表单。 我想通过点击表单中的按钮在当前选项卡页面中打开另一个,当前选项卡的文本将更改。 我使用下面的代码,以便在按下按钮时,当前选项卡页的名称会更改:C#文本在tabcontrol的tabpage中不会更改,c#,tabs,tabcontrol,flicker,C#,Tabs,Tabcontrol,Flicker,我有一些标签页是打开的,每个标签页都是表单。 我想通过点击表单中的按钮在当前选项卡页面中打开另一个,当前选项卡的文本将更改。 我使用下面的代码,以便在按下按钮时,当前选项卡页的名称会更改: private void buttonNewForm_Click(object sender, EventArgs e) { newForm childForm = new newForm(tbc1); //TopLevel for form i
private void buttonNewForm_Click(object sender, EventArgs e)
{
newForm childForm = new newForm(tbc1);
//TopLevel for form is set to false
childForm.TopLevel = false;
//select current TabPage
int curr = tbc1.SelectedIndex;
TabPage tbp = tbc1.TabPages[curr];
tbc1.TabPages[curr].Text = "name of new form";
tbp.Controls.Add(childForm);
//Added form to tabpage
childForm.WindowState = FormWindowState.Maximized;
childForm.Show();
Refresh();
}
它工作得很好,直到我将代码放在主窗体中,以防止我在选项卡上闪烁:
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x02000000; // Turn on WS_EX_COMPOSITED
return cp;
}
}
如何在不删除防止闪烁代码的情况下使其重新工作?要防止闪烁,请尝试此操作
SuspendLayout();
// Add control and make size changes
childForm.Show();
Refresh();
ResumeLayout();
你应该考虑使用一个用户控件而不是一个表单嵌入到一个制表页中。
最后我解决了这个问题。 相反,我不得不使用tbc1.refresh() tbc1是我使用的选项卡控件的名称 在我将所有表单替换为除主表单之外的usecontrols之后,我没有,我需要对上述代码进行一些更改:private void buttonNewForm_Click(object sender, EventArgs e)
{
newForm childForm = new newForm(tbc1);
//select current TabPage
int curr = tbc1.SelectedIndex;
TabPage tbp = tbc1.TabPages[curr];
tbc1.TabPages[curr].Text = "name of new form";
tbp.Focus();
tbp.Controls.Clear();
tbp.Controls.Add(childForm);
tbc1.Refresh();
}
你到底想要什么。您想在tab页中打开另一个表单,还是希望像google chrome浏览器一样使用表格表单构建应用程序?此处需要正确的属性。这也是一个很好的方法让他注意到你的帖子。