G
guilinlzy
Unregistered / Unconfirmed
GUEST, unregistred user!
C#windows forms系列问题之一:TabControl在添加,删除了之后如何保存,以及在特定位置插入tabpage的问题?(附我已写的代码) (20分)<br />不好意思,没什么分了,而且可能会推出很多问题,:)
TabControl在添加,删除了之后如何保存,以及在特定位置插入tabpage的问题(附代码)?
代码如下:
//删除tabpage
private void button2_Click(object sender, System.EventArgs e)
{
tabControl1.Controls.Remove(tabControl1.SelectedTab);
}
//添加tabpage
private void button3_Click(object sender, System.EventArgs e)
{
tabControl1.Controls.Add(new TabPage("newpage"));
}
//在特定位置插入tabpage
private void InsertTab(int tabNumber, ref TabControl tabControl)
{
int limit = tabControl.Controls.Count;
if(tabNumber < 0 || tabNumber > limit)
{
tabControl.Controls.Add(new TabPage("new Page"));
return;
}
int target = tabControl.SelectedIndex;
//save the exisiting pages &
clear the controls
Control [] c = new Control[limit];
tabControl.Controls.CopyTo(c, 0);
tabControl.Controls.Clear();
//add the earlier pages
for (int i = 0;
i < target;
++i)
tabControl.Controls.Add(c);
//insert the page
tabControl.Controls.Add(new TabPage("new Page"));
//add the later pages
for (int i = target;
i < limit;
++i)
tabControl.Controls.Add(c);
//select the new page
tabControl.SelectedIndex = target;
}
//调用插入tabpage
private void btninsert_click(object sender, System.EventArgs e)
{
}
请问在以上代码的基础上如何保存添加删除后的tabpage?
还有如何在 private void btninsert_click(object sender, System.EventArgs e)调用private void InsertTab(int tabNumber, ref TabControl tabControl)
TabControl在添加,删除了之后如何保存,以及在特定位置插入tabpage的问题(附代码)?
代码如下:
//删除tabpage
private void button2_Click(object sender, System.EventArgs e)
{
tabControl1.Controls.Remove(tabControl1.SelectedTab);
}
//添加tabpage
private void button3_Click(object sender, System.EventArgs e)
{
tabControl1.Controls.Add(new TabPage("newpage"));
}
//在特定位置插入tabpage
private void InsertTab(int tabNumber, ref TabControl tabControl)
{
int limit = tabControl.Controls.Count;
if(tabNumber < 0 || tabNumber > limit)
{
tabControl.Controls.Add(new TabPage("new Page"));
return;
}
int target = tabControl.SelectedIndex;
//save the exisiting pages &
clear the controls
Control [] c = new Control[limit];
tabControl.Controls.CopyTo(c, 0);
tabControl.Controls.Clear();
//add the earlier pages
for (int i = 0;
i < target;
++i)
tabControl.Controls.Add(c);
//insert the page
tabControl.Controls.Add(new TabPage("new Page"));
//add the later pages
for (int i = target;
i < limit;
++i)
tabControl.Controls.Add(c);
//select the new page
tabControl.SelectedIndex = target;
}
//调用插入tabpage
private void btninsert_click(object sender, System.EventArgs e)
{
}
请问在以上代码的基础上如何保存添加删除后的tabpage?
还有如何在 private void btninsert_click(object sender, System.EventArgs e)调用private void InsertTab(int tabNumber, ref TabControl tabControl)