private void MyTabItem_OnOnClickEvent(MyTabItem sender, string pagename, bool dark) { _buttonStatus.Baseurl = dark ? "Resources/Icon/ControlBox/dark/" : "Resources/Icon/ControlBox/default/"; if (pagename == null) { return; } if (_userControlDic.ContainsKey(pagename)) { MainContent.Content = _userControlDic[pagename]; } else { switch (pagename) { case "Login": { var page = new MyLogin(); _userControlDic.Add(pagename, page); MainContent.Content = page; break; } case "MainControl": { var page = new MyMainControl(); _userControlDic.Add(pagename, page); MainContent.Content = page; break; } case "Node": { var page = new MyNode(); _userControlDic.Add(pagename, page); MainContent.Content = page; break; } case "Task": { var page = new MyTask(); _userControlDic.Add(pagename, page); MainContent.Content = page; break; } case "Setting": { var page = new MySetting(); _userControlDic.Add(pagename, page); MainContent.Content = page; break; } } } }
// adds a new blank tab private void addTab() { MyTabItem newTab = new MyTabItem(); newTab.ContextMenuUpdate += HandleContextMenu; // event handler newTab.NoteLinkUpdate += HandleNoteLink; // event handler newTab.TextClick += HandleTextUpdate; // event handler tabItems.Add(newTab); // add to collection }
// fires when a new tab is selected private void TabControl_SelectionChanged(object sender, SelectionChangedEventArgs e) { var tc = sender as TabControl; if (tc != null) { MyTabItem item = (MyTabItem)tc.SelectedItem; activeBox = item.Content; } }
//列表控件,鼠标左键双击列表项事件 private void treeView1_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e) { MyTabItem foundTab = null; bool bNewTab = false; //已经有数据读到显示panel中,就设置为可写属性 condition.ReadOnly = false; filterexpression.ReadOnly = false; sortexpression.ReadOnly = false; //根据列表项的内容,找到标签 foreach (TabItem tabItem in tabControl1.Tabs) { if (tabItem.Text == treeView1.SelectedNode.Text) { foundTab = tabItem as MyTabItem; //as语句作为类型转换 } } if (foundTab == null) {//如果没找到标签页 MyTabItem newTab = new MyTabItem(); tabControl1.Tabs.Add(newTab); newTab.Text = treeView1.SelectedNode.Text; tabControlPanel1 = new TabControlPanel(); DataGridView dgv = new DataGridView(); DataView dataView = new DataView(); tabControlPanel1.Dock = DockStyle.Fill; dataView.Table = DS.Tables[treeView1.SelectedNode.Text]; dataView.RowFilter = ""; newTab.AttachedDataView = dataView; //设置表格属性 dgv.AutoGenerateColumns = true; dgv.AllowUserToAddRows = false; dgv.AllowUserToDeleteRows = false; dgv.AllowUserToOrderColumns = false; dgv.DataSource = dataView; dgv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells; for (int i = 5; i < dgv.Columns.Count; i++) { dgv.Columns[i].MinimumWidth = 60; } if (dataView.Table.Columns.Contains("Flg")) { foreach (DataGridViewColumn col in dgv.Columns) { if (col.Name == "Flg") { col.MinimumWidth = 70 ; } } } dgv.Location = new Point(0, 0); dgv.Dock = DockStyle.Fill; newTab.AttachedDataGridview = dgv; DisableAutoSort(dgv); tabControlPanel1.Controls.Add(dgv); newTab.AttachedControl = tabControlPanel1; foundTab = newTab; bNewTab = true; } //表格显示 tabControl1.SelectedTab = foundTab; tabControl1.SelectedPanel = foundTab.AttachedControl as TabControlPanel; if (bNewTab)//如果是新的标签页,则添加到控件中(个人感觉这句话放在上面大if里比较好) { tabControl1.Controls.Add(tabControl1.SelectedPanel); } tabControl1.SelectedPanel.Show();//显示表格 //填充字段选择下拉列表 fields.SelectedIndex = foundTab.fieldIndex; }