1,首先展示一下导航页
2, 其实导航页制作比较简单,就是Button按钮 比如站点管理按钮设置以下几个属性即可
BackColor :背景色
Font :字体设置
3,导航按钮如何点击打开页面的代码实现如下 以 站点管理为例
private void btnStation_Click(object sender, EventArgs e)
{
//TabControl mainTab = this.Parent.Parent as TabControl;
this.ShowNavForm<BM.FrmStationList>();
}
4,展示ShowNavForm方法
public static void ShowNavForm<T>(this Form curForm,object obj=null) where T:Form
{
TabControl tab = curForm.Parent.Parent as TabControl;
tab.ShowTabFormPage<T>();
}
5,展示ShowTabFormPage方法
public static void ShowTabFormPage<T>(this TabControl tab) where T:Form
{
Form frm = Activator.CreateInstance<T>();
tab.AddTabFormPage(frm);
}
6,展示AddTabFormPage方法 添加窗体到选项卡中
public static void AddTabFormPage(this TabControl tab,Form form,int index=-1)
{
TabPage page = null;
Form frm = GetOpenForm(form.Name);
if (frm==null)
{
frm = form;
frm.FormBorderStyle = FormBorderStyle.None;
frm.TopLevel = false;
frm.WindowState = FormWindowState.Maximized;
page = new TabPage();
frm.Parent = page;
frm.Dock = DockStyle.Fill;
page.Name = frm.Name;
page.Text = frm.Text;
if (index != -1)
tab.TabPages.Insert(index, page);
else
tab.TabPages.Add(page);
frm.Show();
}
else
{
page = tab.TabPages[frm.Name];
}
tab.SelectedTab = page;
}
以上就是系统导航页实现的全部代码,大家感兴趣关注下面订阅号,后面更新代码大部分在订阅号更新。