梦想农场

contextmenustrip控件 statusstrip控件

梦想农场 1

关于contextmenustrip控件,statusstrip控件这个很多人还不知道,今天欣欣来为大家解答以上的问题,现在让我们一起来看看吧!

contextmenustrip控件 statusstrip控件contextmenustrip控件 statusstrip控件


contextmenustrip控件 statusstrip控件


1、this.ToolStripMenuItem2});这个貌似不难,右键菜单用代码生成就行了。

2、this.工ToolStripMenuItem1.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {你是要用ContextMenuStrip控件,生成的菜单可以用代码控制。

3、如Control c = fruitContextMenuStrip.SourceControl as Control;// It also demonstrates dynamic addition and dynamic// SourceControl determination with reuse.class Form3 : Formprivate ContextMenuStrip fruitContextMenuStrip;public Form3(){// Create a new ContextMenuStrip control.fruitContextMenuStrip = new ContextMenuStrip();// Attach an nt handler for the// ContextMenuStrip control's Opening nt.fruitContextMenuStrip.Opening += new System.ComponentModel.CancelEventHandler(cms_Opening);ToolStrip ts = new ToolStrip();// Create a ToolStripDropDownButton control and add it// to the ToolStrip control's Items collections.ToolStripDropDownButton fruitToolStripDropDownButton = new ToolStripDropDownButton("Fruit", null, null, "Fruit");ts.Items.Add(fruitToolStripDropDownButton);// Dock the ToolStrip control to the top of the form.ts.Dock = DockStyle.Top;// Assign the ContextMenuStrip control as the// ToolStripDropDownButton control's DropDown menu.fruitToolStripDropDownButton.DropDown = fruitContextMenuStrip;// Create a new MenuStrip control and add a ToolStripMenuItem.MenuStrip ms = new MenuStrip();ms.Items.Add(fruitToolStripMenuItem);// Dock the MenuStrip control to the top of the form.ms.Dock = DockStyle.Top;// Assign the MenuStrip control as the// ToolStripMenuItem's DropDown menu.fruitToolStripMenuItem.DropDown = fruitContextMenuStrip;// Assign the ContextMenuStrip to the form's// ContextMenuStrip property.this.ContextMenuStrip = fruitContextMenuStrip;// Add the ToolStrip control to the Controls collection.this.Controls.Add(ts);//Add a button to the form and assign its ContextMenuStrip.Button b = new Button();this.Controls.Add(b);b.ContextMenuStrip = fruitContextMenuStrip;// Add the MenuStrip control last.// This is important for correct placement in the z-order.this.Controls.Add(ms);}// This nt handler is invoked when the ContextMenuStrip// control's Opening nt is raised. It demonstrates// determination with reuse.void cms_Opening(object sender, System.ComponentModel.CancelEventArgs e){// Acquire references to the owning control and .ToolStripDropDownItem tsi = fruitContextMenuStrip.OwnerItem as ToolStripDropDownItem;// Clear the ContextMenuStrip control's Items collection.// Check the source control first.if (c != null){// Add custom (Form)fruitContextMenuStrip.Items.Add("Source: " + c.GetType().ToString());}else if (tsi != null)fruitContextMenuStrip.Items.Add("Source: " + tsi.GetType().ToString());}// Populate the ContextMenuStrip control with its default s.fruitContextMenuStrip.Items.Add("-");fruitContextMenuStrip.Items.Add("Oranges");fruitContextMenuStrip.Items.Add("Pears");// Set Cancel to false.}}。

本文到这结束,希望上面文章对大家有所帮助。