.NET Winform 将页面完美地嵌入到TabControl中
时间:2011-03-26 来源:24 3 8
我们经常用的浏览器都是分页式的操作起来很方便,当然我们希望能把其加入到我们的程序中来,其实实现起来很简单,先不废话上图先:
当然也要有右键和双击事件了:
是不是看着还行,源码如下:
private void tvMain_MouseClick(object sender, MouseEventArgs e)我发现我的【关闭其它】按钮写的很糟糕,不过也实现了功能,希望有时间好好修改下吧。本文所用的控件是DotNetBar,微软的分页也是一样的,主要是页面的TopLevel属性设置为Fales就可以嵌入到分页中去了。
{
DevComponents.DotNetBar.TabItem tabItemNew = new DevComponents.DotNetBar.TabItem();
DevComponents.DotNetBar.TabControlPanel tabControlPanelNew = new DevComponents.DotNetBar.TabControlPanel();
tabControlPanelNew.Dock = System.Windows.Forms.DockStyle.Fill;
tabControlPanelNew.Name = "TestPanle";
tabControlPanelNew.TabItem = tabItemNew;
tabItemNew.AttachedControl = tabControlPanelNew;
tabItemNew.Name = "TestItem";
tabItemNew.Text = "测试";
tabControlMain.Controls.Add(tabControlPanelNew);
tabControlMain.Tabs.Add(tabItemNew);
mdiForm.FormBorderStyle = FormBorderStyle.None;//mdiForm为窗体实例
mdiForm.TopLevel = false;
mdiForm.Parent = tabControlPanelNew;
mdiForm.Dock = DockStyle.Fill;
tabControlPanelNew.Controls.Add(mdiForm);
mdiForm.Show();
tabControlMain.Refresh();
tabControlMain.SelectedTab = tabItemNew;
}
}
private void tsMenuItemCloseAll_Click(object sender, EventArgs e)
{
int i = 1;
while (tabControlMain.Tabs.Count > 1)
{
if (tabControlMain.SelectedTabIndex == 1)
{
i = 2;
}
if (i == 2 && tabControlMain.Tabs.Count == 2)
{
break;
}
TabItem ti = tabControlMain.Tabs[i];
tabControlMain.Tabs.Remove(ti);
ti.Dispose();
}
tabControlMain.Refresh();
}
相关阅读 更多 +