当前位置:IT168首页 > 技术开发 > 概述
[收藏此页] [打印] [推荐] [评论]

将MDI子窗体加入ToolScrip

责任编辑:nancy作者:ITPUB论坛   2008-07-11   
文本Tag: 微软 sql

【IT168技术文档】

1using System; 2using System.Collections.Generic; 3using System.ComponentModel; 4using System.Data; 5using System.Drawing; 6using System.Text; 7using System.Windows.Forms; 8 9namespace WindowsApplication2 10{ 11 public partial class Form1 : Form 12 { 13 public Form1() 14 { 15 InitializeComponent(); 16 17 } 18 19 private void toolStripButton1_Click(object sender, EventArgs e) 20 { 21 Form2 form = new Form2(); 22 ToolStripMenuItem item = new ToolStripMenuItem((this.MdiChildren.Length + 1).ToString()); 23 toolStripDropDownButton1.DropDownItems.Add(item); 24 form.MdiParent = this; 25 form.Text = item.Text; 26 ToolMenuItemEven rm = new ToolMenuItemEven(this, form, item); 27 form.Show(); 28 } 29 } 30 31 public class ToolMenuItemEven 32 { 33 private Form form = null; 34 ToolStripMenuItem item = null; 35 private Form1 mdiForm; 36 37 public ToolMenuItemEven(Form1 mdiForm, Form fm, ToolStripMenuItem item) 38 { 39 this.mdiForm = mdiForm; 40 this.form = fm; 41 this.item = item; 42 fm.Disposed += new EventHandler(RemoveItem); 43 item.Click += new EventHandler(ItemClick); 44 ItemClearCheck(); 45 item.Checked = true; 46 item = null; 47 fm = null; 48 } 49 50 private void RemoveItem(object obj, EventArgs e) 51 { 52 if (mdiForm != null) 53 { 54 mdiForm.toolStripDropDownButton1.DropDownItems.Remove(item); 55 } 56 } 57 58 private void ItemClick(object sender, EventArgs e) 59 { 60 if (form != null && item != null) 61 { 62 form.Activate(); 63 ItemClearCheck(); 64 item.Checked = true; 65 } 66 } 67 68 private void ItemClearCheck() 69 { 70 foreach (ToolStripMenuItem it in mdiForm.toolStripDropDownButton1.DropDownItems) 71 { 72 it.Checked = false; 73 } 74 } 75 } 76}
上一页
1
下一页
收藏到: 添加到“百度搜藏”添加到“QQ书签”添加到“Google书签”添加到“Yahoo收藏”添加到“和讯网摘”
【内容导航】
本文欢迎转载,转载请注明:转载自IT168 [ http://www.it168.com/ ]
本文链接:http://tech.it168.com/d/2008-07-11/200807111339395.shtml
技术开发相关文章  
  • 暂无
友情推介