我有一些选项卡处于打开状态,并且每个选项卡页面都处于监禁状态。我想通过单击表单中的按钮在当前选项卡页面中打开另一个,当前选项卡的文本将更改。我使用下面的代码,以便如果按下按钮,则当前标签页的名称将更改:
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;
}
}
如何在不删除防止闪烁的代码的情况下再次工作?
最后我解决了这个问题。相反,refresh()我不得不使用tbc1.refresh()
tbc1是我使用的tabcontrol的名称。
在将所有表单替换为主表单之外的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();
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句