本文整理汇总了C#中System.Windows.Forms.MenuItem.CloneMenu方法的典型用法代码示例。如果您正苦于以下问题:C# MenuItem.CloneMenu方法的具体用法?C# MenuItem.CloneMenu怎么用?C# MenuItem.CloneMenu使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.MenuItem
的用法示例。
在下文中一共展示了MenuItem.CloneMenu方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CloneWindowMenuTest
public void CloneWindowMenuTest ()
{
MenuItem menuitem1 = new MenuItem ();
menuitem1.MdiList = true;
MenuItem menuitem2 = menuitem1.CloneMenu ();
Assert.IsTrue (menuitem2.MdiList, "#1");
}
示例2: CopyMenu
/// ------------------------------------------------------------------------------------
/// <summary>
/// Create a copy of the menu item and all its sub-menu items by cloning it and
/// initializing the menu extender properties.
/// </summary>
/// <param name="src"></param>
/// <param name="fRemoveSrc"><c>true</c> to remove old menu item from menu extender
/// (as when merging, as opposed to cloning, menus)</param>
/// <returns></returns>
/// ------------------------------------------------------------------------------------
internal MenuItem CopyMenu(MenuItem src, bool fRemoveSrc)
{
MenuItem menuItem = src.CloneMenu();
// we want to deal with the sub-menu items separately, so get rid of those that
// CloneMenu created. Unfortunately there's no way to clone only the menu item but
// not the sub-menu items.
menuItem.MenuItems.Clear();
m_menuExtender.InitializeMenuItem(src, menuItem, fRemoveSrc);
MergeMenu(menuItem, src);
return menuItem;
}
示例3: ItemsChanged
internal void ItemsChanged(int change, MenuItem item)
{
if (((change == 4) && (this.data != null)) && ((this.data.baseItem != null) && this.data.baseItem.MenuItems.Contains(item)))
{
if ((this.menu != null) && this.menu.created)
{
this.UpdateMenuItem(true);
base.CreateMenuItems();
}
else if (this.data != null)
{
for (MenuItem item2 = this.data.firstItem; item2 != null; item2 = item2.nextLinkedItem)
{
if (item2.created)
{
MenuItem item3 = item.CloneMenu();
item.data.AddItem(item3);
item2.MenuItems.Add(item3);
return;
}
}
}
}
}
示例4: CloneMenu
public virtual MenuItem CloneMenu()
{
MenuItem item = new MenuItem();
item.CloneMenu(this);
return item;
}
示例5: CloneEventTest
public void CloneEventTest ()
{
MenuItem mi1, mi2;
event_reached = false;
mi1 = new MenuItem ();
mi1.Click += new EventHandler (event_test);
mi2 = mi1.CloneMenu ();
mi2.PerformClick ();
Assert.IsTrue (event_reached);
event_reached = false;
mi1 = new MenuItem ();
mi1.Select += new EventHandler (event_test);
mi2 = mi1.CloneMenu ();
mi2.PerformSelect ();
Assert.IsTrue (event_reached);
#if no
// these three can't be tested because of the broken MenuItem.CloneMenu
event_reached = false;
mi1 = new MenuItem ();
mi1.Popup += new EventHandler (test_event);
mi2 = mi1.CloneMenu ();
mi2.PerformPopup ();
Assert.IsTrue (event_reached);
event_reached = false;
mi1 = new MenuItem ();
mi1.DrawItem += new DrawItemEventHandler (test_drawevent);
mi2 = mi1.CloneMenu ();
mi2.PerformDrawItem (new DrawItemEventArgs (null, null, Rectangle.Empty, 1, DrawItemState.None));
Assert.IsTrue (event_reached);
event_reached = false;
mi1 = new MenuItem ();
mi1.MeasureItem += new MeasureItemEventHandler (test_measureevent);
mi2 = mi1.CloneMenu ();
mi2.PerformMeasureItem (new MeasureItemEventArgs (null, 1));
Assert.IsTrue (event_reached);
#endif
}
示例6: CloneTest
public void CloneTest ()
{
MenuItem mi1, mi2;
mi1 = new MenuItem();
mi1.BarBreak = true;
mi1.Break = true;
mi1.Checked = true;
mi1.DefaultItem = true;
mi1.Enabled = true;
mi1.MergeOrder = 1;
mi1.MergeType = MenuMerge.Replace;
mi1.OwnerDraw = true;
mi1.RadioCheck = true;
mi1.Shortcut = Shortcut.Alt0;
mi1.ShowShortcut = true;
mi1.Text = "text1";
mi1.Visible = true;
mi1.Name = "name1";
mi1.Tag = "tag1";
mi2 = mi1.CloneMenu();
Assert.AreEqual(mi1.BarBreak, mi2.BarBreak, "BarBreak #1");
Assert.AreEqual(mi1.Break, mi2.Break, "Break #1");
Assert.AreEqual(mi1.Checked, mi2.Checked, "Checked #1");
Assert.AreEqual(mi1.DefaultItem, mi2.DefaultItem, "DefaultItem #1");
Assert.AreEqual(mi1.Enabled, mi2.Enabled, "Enabled #1");
Assert.AreEqual(mi1.MergeOrder, mi2.MergeOrder, "MergeOrder #1");
Assert.AreEqual(mi1.MergeType, mi2.MergeType, "MergeType #1");
Assert.AreEqual(mi1.OwnerDraw, mi2.OwnerDraw, "OwnerDraw #1");
Assert.AreEqual(mi1.RadioCheck, mi2.RadioCheck, "RadioCheck #1");
Assert.AreEqual(mi1.Shortcut, mi2.Shortcut, "Shortcut #1");
Assert.AreEqual(mi1.ShowShortcut, mi2.ShowShortcut, "ShowShortcut #1");
Assert.AreEqual(mi1.Text, mi2.Text, "Text #1");
Assert.AreEqual(mi1.Visible, mi2.Visible, "Visible #1");
Assert.AreEqual(mi1.Name, mi2.Name, "Name #1");
Assert.AreEqual(mi1.Tag, mi2.Tag, "Tag #1");
mi1.BarBreak = false;
mi1.Break = false;
mi1.Checked = false;
mi1.DefaultItem = false;
mi1.Enabled = false;
mi1.MergeOrder = 0;
mi1.MergeType = MenuMerge.Remove;
mi1.OwnerDraw = false;
mi1.RadioCheck = false;
mi1.Shortcut = Shortcut.Alt1;
mi1.ShowShortcut = false;
mi1.Text = "text2";
mi1.Visible = false;
mi1.Name = "name2";
mi1.Tag = "tag2";
mi2 = mi1.CloneMenu();
Assert.AreEqual(mi1.BarBreak, mi2.BarBreak, "BarBreak #2");
Assert.AreEqual(mi1.Break, mi2.Break, "Break #2");
Assert.AreEqual(mi1.Checked, mi2.Checked, "Checked #2");
Assert.AreEqual(mi1.DefaultItem, mi2.DefaultItem, "DefaultItem #2");
Assert.AreEqual(mi1.Enabled, mi2.Enabled, "Enabled #2");
Assert.AreEqual(mi1.MergeOrder, mi2.MergeOrder, "MergeOrder #2");
Assert.AreEqual(mi1.MergeType, mi2.MergeType, "MergeType #2");
Assert.AreEqual(mi1.OwnerDraw, mi2.OwnerDraw, "OwnerDraw #2");
Assert.AreEqual(mi1.RadioCheck, mi2.RadioCheck, "RadioCheck #2");
Assert.AreEqual(mi1.Shortcut, mi2.Shortcut, "Shortcut #2");
Assert.AreEqual(mi1.ShowShortcut, mi2.ShowShortcut, "ShowShortcut #2");
Assert.AreEqual(mi1.Text, mi2.Text, "Text #2");
Assert.AreEqual(mi1.Visible, mi2.Visible, "Visible #2");
Assert.AreEqual(mi1.Name, mi2.Name, "Name #2");
Assert.AreEqual(mi1.Tag, mi2.Tag, "Tag #2");
}
示例7: CloneMenu
/// <include file='doc\MenuItem.uex' path='docs/doc[@for="MenuItem.CloneMenu"]/*' />
/// <devdoc>
/// <para>
/// Creates and returns an identical copy of this menu item.
/// </para>
/// </devdoc>
public virtual MenuItem CloneMenu() {
MenuItem newItem = new MenuItem();
newItem.CloneMenu(this);
return newItem;
}
示例8: ItemsChanged
internal void ItemsChanged(int change, MenuItem item) {
if (change == CHANGE_ITEMADDED &&
this.data != null &&
this.data.baseItem != null &&
this.data.baseItem.MenuItems.Contains(item)) {
if (menu != null && menu.created) {
UpdateMenuItem(true);
CreateMenuItems();
} else if (this.data != null) {
MenuItem currentMenuItem = this.data.firstItem;
while (currentMenuItem != null) {
if (currentMenuItem.created) {
MenuItem newItem = item.CloneMenu();
item.data.AddItem(newItem);
currentMenuItem.MenuItems.Add(newItem);
// newItem.menu = currentMenuItem;
// newItem.CreateMenuItem();
break;
}
currentMenuItem = currentMenuItem.nextLinkedItem;
}
}
}
}
示例9: InitializeComponent
//.........这里部分代码省略.........
menuItemRename } );
menuItemResources.Text = "Resources";
// menuItemAddString
menuItemAddString.Index = 0;
menuItemAddString.Text = "Add S&tring";
menuItemAddString.Click += new EventHandler( OnMenuItemAddStringClick );
// menuItemAddFiles
menuItemAddFiles.Index = 1;
menuItemAddFiles.Text = "Add Fi&le(s)";
menuItemAddFiles.Click += new EventHandler( OnMenuItemAddFilesClick );
// menuItemAddColor
menuItemAddColor.Index = 2;
menuItemAddColor.Text = "Add Colo&r";
menuItemAddColor.Click += new EventHandler( OnMenuItemAddColorClick );
// menuItemDash2
menuItemDash2.Index = 3;
menuItemDash2.Text = "-";
// menuItemDelete
menuItemDelete.Index = 4;
menuItemDelete.Text = "&Delete";
menuItemDelete.Click += new EventHandler( OnMenuItemDeleteClick );
// menuItemCopy
menuItemCopy.Index = 5;
menuItemCopy.Text = "&Copy";
menuItemCopy.Click += new EventHandler( OnMenuItemCopyClick );
// menuItemPaste
menuItemPaste.Index = 6;
menuItemPaste.Text = "Paste";
menuItemPaste.Click += new EventHandler( OnMenuItemPasteClick );
menuItemDash3.Index = 7;
menuItemDash3.Text = "-";
menuItemRename.Index = 8;
menuItemRename.Text = "Rename";
menuItemRename.Click += new EventHandler( OnMenuItemRenameClick );
// menuItemHelp
menuItemHelp.Index = 2;
menuItemHelp.MenuItems.AddRange( new MenuItem[] {
menuItemAbout} );
menuItemHelp.Text = "&Help";
// menuItemAbout
menuItemAbout.Index = 0;
menuItemAbout.Text = "A&bout";
menuItemAbout.Click += new EventHandler( OnMenuItemAboutClick );
// mainMenu
mainMenu.MenuItems.AddRange( new MenuItem[] {
menuItemFile,
menuItemResources,
menuItemHelp} );
// resourceControl
resourceControl.Dock = DockStyle.Fill;
resourceControl.InternalContextMenu.MenuItems.AddRange( new MenuItem[] {
menuItemAddString.CloneMenu( ),
menuItemAddFiles.CloneMenu( ),
menuItemAddColor.CloneMenu( ),
menuItemDash2.CloneMenu( ),
menuItemDelete.CloneMenu( ),
menuItemCopy.CloneMenu( ),
menuItemPaste.CloneMenu( ),
menuItemRename.CloneMenu( )
} );
// statusBar
StatusBarPanel panel1 = new StatusBarPanel( );
StatusBarPanel panel2 = new StatusBarPanel( );
panel1.BorderStyle = StatusBarPanelBorderStyle.Sunken;
panel1.AutoSize = StatusBarPanelAutoSize.Spring;
panel2.BorderStyle = StatusBarPanelBorderStyle.Sunken;
panel2.AutoSize = StatusBarPanelAutoSize.Spring;
statusBar.ShowPanels = true;
statusBar.Panels.Add( panel1 );
statusBar.Panels.Add( panel2 );
resourceControl.ParentStatusBar = statusBar;
// MainForm
// AutoScaleBaseSize = new Size( 5, 14 );
ClientSize = new Size( 592, 541 );
Menu = mainMenu;
Text = "New Resource.resx";
ResumeLayout( false );
Controls.Add( resourceControl );
Controls.Add( statusBar );
}
示例10: settingsToolStripMenuItem_Click
private void settingsToolStripMenuItem_Click(object sender, EventArgs e)
{
////remove controls
int x = 0;
try
{
foreach (Label control in CurrentConfig.Controls )
{
CurrentConfig.Controls.Remove(control);
control.Dispose();
x++;
}
CurrentConfig.Dispose();
}
catch
{
///first run, ignore
}
////show current configuration
CurrentConfig = new GroupBox();
CurrentConfig.Text = "Current Configuration";
CurrentConfig.Location = new System.Drawing.Point(31, 27);
CurrentConfig.Size = new System.Drawing.Size(452, 114);
CurrentConfig.Name="CurrentConfig";
settings.Controls.Add(CurrentConfig);
Label[] currentconfig=null;
ContextMenu[] ConfigMenu = null;
Array.Resize(ref ConfigMenu, Configuration.Length);
Array.Resize(ref currentconfig, Configuration.Length);
MenuItem Edit = new MenuItem();
MenuItem Remove = new MenuItem();
MenuItem Current = new MenuItem();
Edit.Text="Edit Item";
Edit.Click+=new EventHandler(Edit_Click);
Remove.Text="Remove";
Remove.Click+=new EventHandler(Remove_Click);
x = 0;
int ylocation = 0;
try
{
foreach (Button config in Menu)
{
///// create grid ///
currentconfig[x] = new Label();
if (ylocation < CurrentConfig.Size.Height)
{
if (x > 0)
{
currentconfig[x].Location = new System.Drawing.Point(currentconfig[x - 1].Location.X, currentconfig[x - 1].Location.Y + 33);
ylocation = currentconfig[x].Location.Y + 30+ currentconfig[x].Size.Height ;
}
else
{
currentconfig[x].Location = new System.Drawing.Point(15, 15);
}
}
else
{
currentconfig[x].Location = new System.Drawing.Point(currentconfig[x - 1].Location.X+50,15);
ylocation = currentconfig[x].Location.Y + 30;
}
///// make new menu for each config
ConfigMenu[x] = new ContextMenu();
Current.Text = Menu[x].Name;
ConfigMenu[x].MenuItems.Add(0, Current.CloneMenu());
ConfigMenu[x].MenuItems.Add("-");
ConfigMenu[x].MenuItems.Add(2, Edit.CloneMenu());
ConfigMenu[x].MenuItems.Add(3, Remove.CloneMenu());
ConfigMenu[x].MenuItems[2].Name = "Edit" + x;
ConfigMenu[x].MenuItems[3].Name = "Remove" + x;
///add images to menus
AddImageToMenuItem(ConfigMenu[x].MenuItems[3], SystemIcons.Error.Handle, true);
AddImageToMenuItem(ConfigMenu[x].MenuItems[2], SystemIcons.Asterisk.Handle, true);
AddImageToMenuItem(ConfigMenu[x].MenuItems[0], Icon.ExtractAssociatedIcon(Configuration[x]).Handle, false);
//// add images to configs
currentconfig[x].Image = new Bitmap(Icon.ExtractAssociatedIcon(Configuration[x]).ToBitmap());
currentconfig[x].BorderStyle = BorderStyle.Fixed3D;
currentconfig[x].Size = currentconfig[x].Image.Size;
currentconfig[x].Name = x.ToString();
currentconfig[x].ContextMenu = ConfigMenu[x];
currentconfig[x].MouseHover += new EventHandler(currentconfig_MouseHover);
//.........这里部分代码省略.........