首页 > 代码库 > winform 页面设计(一)
winform 页面设计(一)
code:
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using TX.Framework.WindowUI.Controls;using TX.Framework.WindowUI.Forms;namespace WindowsTest{ public partial class Form5 : test1 { private List<Form> listExistFrm = new List<Form>(); static List<TabPage> listExistPage = new List<TabPage>(); public Form5() { InitializeComponent(); } private void Form5_Load(object sender, EventArgs e) { XPanderPanel xpanderPanel = new XPanderPanel(); xpanderPanel.Text = "系统模块"; int captionHeight = xpanderPanel.CaptionHeight; xpanderPanel.Expand = true; for (int i = 5; i > 0; i--) { TXButton txtbtn = new TXButton(); int btnhegiht = txtbtn.Height; //if (i > 0) //{ // txtbtn.Location = new Point(0, captionHeight + btnhegiht*i); //} //else { // txtbtn.Location = new Point(0,captionHeight); //} txtbtn.Dock = DockStyle.Top;//设置这个属性不需要计算显示距离,需要倒序 txtbtn.Text = "测试"+i; txtbtn.Tag = i; txtbtn.Click += new EventHandler(btntest_Click); xpanderPanel.Controls.Add(txtbtn); } this.xPanderPanelList1.XPanderPanels.Add(xpanderPanel); XPanderPanel xpanderPanel2 = new XPanderPanel(); xpanderPanel2.Text = "开发模块"; xpanderPanel2.Expand = false; for (int i = 5; i > 0; i--) { TXButton txtbtn = new TXButton(); int btnhegiht = txtbtn.Height; txtbtn.Dock = DockStyle.Top; txtbtn.Text = "开发" + i; txtbtn.Tag = "开发" + i; txtbtn.Click += new EventHandler(btntest_Click); xpanderPanel2.Controls.Add(txtbtn); } this.xPanderPanelList1.XPanderPanels.Add(xpanderPanel2); AddTbList(); } void AddTbList() { foreach (TabPage tp in this.txTabControl1.TabPages) { listExistPage.Add(tp); } } private void btntest_Click(object sender, EventArgs e) { string tag = (sender as TXButton).Tag.ToString(); //MessageBox.Show("hello word" + tag); TabPage tb = new TabPage(); tb.Text = tag; List<TabPage> listtp = listExistPage.Where(t=>t.Text==tag).ToList(); if (listtp.Count==0) {//没在集合中出现追加 listExistPage.Add(tb); this.txTabControl1.TabPages.Add(tb); this.txTabControl1.SelectedTab = tb;// 选中 } } private void toolStripMenuItem1_Click(object sender, EventArgs e) {//关闭当前选中的tabpage页 listExistPage.Remove(this.txTabControl1.SelectedTab); this.txTabControl1.SelectedTab.Dispose(); } private void toolStripMenuItem2_Click(object sender, EventArgs e) { foreach (TabPage tp in this.txTabControl1.TabPages) { if (this.txTabControl1.SelectedTab.Text == tp.Text) continue; listExistPage.Remove(tp); tp.Dispose(); //关闭全部tabpage 页 } } private void 关闭所有文档ToolStripMenuItem_Click(object sender, EventArgs e) { foreach (TabPage tp in this.txTabControl1.TabPages) { listExistPage.Remove(tp); tp.Dispose(); //关闭全部tabpage 页 } } private void txTabControl1_Selected(object sender, TabControlEventArgs e) {//选项卡顶部切换 // this.txTabControl1.ContextMenuStrip = contextMenuStrip1; } private void txTabControl1_MouseDoubleClick(object sender, MouseEventArgs e) {//鼠标双击关闭选项卡页面 listExistPage.Remove(this.txTabControl1.SelectedTab); this.txTabControl1.SelectedTab.Dispose(); } private void txButton1_Click(object sender, EventArgs e) { Form7 f7 = new Form7(); f7.ShowDialog(); } }}
winform 页面设计(一)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。