The method can be slightly altered to give the same desired effect. Thanks to your code, I have now worked out how to use it in mine. This is how I will use it. First, create a function that returns a new clone of the item entered into the argument.
public ToolStripMenuItem CrudeClone(ToolStripMenuItem itemToClone)
{
// dirt simple clone - just properties, no subitems
ToolStripMenuItem clonedItem = new ToolStripMenuItem();
clonedItem.Events.AddHandlers(this.Events);
clonedItem.AccessibleName = itemToClone.AccessibleName;
clonedItem.AccessibleRole = itemToClone.AccessibleRole;
clonedItem.Alignment = itemToClone.Alignment;
clonedItem.AllowDrop = itemToClone.AllowDrop;
clonedItem.Anchor = itemToClone.Anchor;
clonedItem.AutoSize = itemToClone.AutoSize;
clonedItem.AutoToolTip = itemToClone.AutoToolTip;
clonedItem.BackColor = itemToClone.BackColor;
clonedItem.BackgroundImage = itemToClone.BackgroundImage;
clonedItem.BackgroundImageLayout = itemToClone.BackgroundImageLayout;
clonedItem.Checked = itemToClone.Checked;
clonedItem.CheckOnClick = itemToClone.CheckOnClick;
clonedItem.CheckState = itemToClone.CheckState;
clonedItem.DisplayStyle = itemToClone.DisplayStyle;
clonedItem.Dock = itemToClone.Dock;
clonedItem.DoubleClickEnabled = itemToClone.DoubleClickEnabled;
clonedItem.Enabled = itemToClone.Enabled;
clonedItem.Font = itemToClone.Font;
clonedItem.ForeColor = itemToClone.ForeColor;
clonedItem.Image = itemToClone.Image;
clonedItem.ImageAlign = itemToClone.ImageAlign;
clonedItem.ImageScaling = itemToClone.ImageScaling;
clonedItem.ImageTransparentColor = itemToClone.ImageTransparentColor;
clonedItem.Margin = itemToClone.Margin;
clonedItem.MergeAction = itemToClone.MergeAction;
clonedItem.MergeIndex = itemToClone.MergeIndex;
clonedItem.Name = itemToClone.Name;
clonedItem.Overflow = itemToClone.Overflow;
clonedItem.Padding = itemToClone.Padding;
clonedItem.RightToLeft= itemToClone.RightToLeft;
clonedItem.ShortcutKeys = itemToClone.ShortcutKeys;
clonedItem.ShowShortcutKeys = itemToClone.ShowShortcutKeys;
clonedItem.Tag = itemToClone.Tag;
clonedItem.Text = itemToClone.Text;
clonedItem.TextAlign = itemToClone.TextAlign;
clonedItem.TextDirection = itemToClone.TextDirection;
clonedItem.TextImageRelation = itemToClone.TextImageRelation;
clonedItem.ToolTipText = itemToClone.ToolTipText;
clonedItem.Available = itemToClone.Available;
if (!itemToClone.AutoSize)
{
clonedItem.Size = itemToClone.Size;
}
return clonedItem;
}
Then I will call this in the main form as:
ToolStripMenuItem itemToClone = new ToolStripMenuItem();
///
// Do whatever in the meantime to that item
///
ToolStripMenuItem clonedItem = CrudeClone(itemToClone);
I hope that helps.
AAaron123 wrote:
I forgot to insert the code.
01-Apr-08
I forgot to insert the code
The code mentioned above is:
public toolStripMenuItem Clone() {
// dirt simple clone - just properties, no subitems
ToolStripMenuItem menuItem = new ToolStripMenuItem();
menuItem.Events.AddHandlers(this.Events);
menuItem.AccessibleName = this.AccessibleName;
menuItem.AccessibleRole = this.AccessibleRole;
menuItem.Alignment = this.Alignment;
menuItem.AllowDrop = this.AllowDrop;
menuItem.Anchor = this.Anchor;
menuItem.AutoSize = this.AutoSize;
menuItem.AutoToolTip = this.AutoToolTip;
menuItem.BackColor = this.BackColor;
menuItem.BackgroundImage = this.BackgroundImage;
menuItem.BackgroundImageLayout = this.BackgroundImageLayout;
menuItem.Checked = this.Checked;
menuItem.CheckOnClick = this.CheckOnClick;
menuItem.CheckState = this.CheckState;
menuItem.DisplayStyle = this.DisplayStyle;
menuItem.Dock = this.Dock;
menuItem.DoubleClickEnabled = this.DoubleClickEnabled;
menuItem.Enabled = this.Enabled;
menuItem.Font = this.Font;
menuItem.ForeColor = this.ForeColor;
menuItem.Image = this.Image;
menuItem.ImageAlign = this.ImageAlign;
menuItem.ImageScaling = this.ImageScaling;
menuItem.ImageTransparentColor = this.ImageTransparentColor;
menuItem.Margin = this.Margin;
menuItem.MergeAction = this.MergeAction;
menuItem.MergeIndex = this.MergeIndex;
menuItem.Name = this.Name;
menuItem.Overflow = this.Overflow;
menuItem.Padding = this.Padding;
menuItem.RightToLeft= this.RightToLeft;
menuItem.ShortcutKeys = this.ShortcutKeys;
menuItem.ShowShortcutKeys = this.ShowShortcutKeys;
menuItem.Tag = this.Tag;
menuItem.Text = this.Text;
menuItem.TextAlign = this.TextAlign;
menuItem.TextDirection = this.TextDirection;
menuItem.TextImageRelation = this.TextImageRelation;
menuItem.ToolTipText = this.ToolTipText;
menuItem.Available = menuItem.Available;
if (!AutoSize) {
menuItem.Size = this.Size;
}
return menuItem;
}
Posted by Microsoft on 7/11/2005 at 10:43 AM
Previous Posts In This Thread:
Add a clone property to the ToolStripMenuItem?
There is some code that can be found by googling "dirt simple clone" for
cloning a ToolStripMenuItem. It's quite old. Posted by Ron of the .NET
Client Team in 2005.
I don't see how that helps because I don't know how to convince the Designer
to use that type instead of the regular ToolStripMenuItem.
Has things gotten better in VS2008?
Does anyone know how to obtain a clone of a ToolStripMenuItem that the
Designer adds to a menu?
Is it possible to add a new property to the existing ToolStripMenuItem? The
code from Ron might work if it could be included somehow?
I'd appreciate any suggestions of what I might experiment with.
I forgot to insert the code.
I forgot to insert the code.
The code mentioned above is:
public toolStripMenuItem Clone() {
// dirt simple clone - just properties, no subitems
ToolStripMenuItem menuItem = new ToolStripMenuItem();
menuItem.Events.AddHandlers(this.Events);
menuItem.AccessibleName = this.AccessibleName;
menuItem.AccessibleRole = this.AccessibleRole;
menuItem.Alignment = this.Alignment;
menuItem.AllowDrop = this.AllowDrop;
menuItem.Anchor = this.Anchor;
menuItem.AutoSize = this.AutoSize;
menuItem.AutoToolTip = this.AutoToolTip;
menuItem.BackColor = this.BackColor;
menuItem.BackgroundImage = this.BackgroundImage;
menuItem.BackgroundImageLayout = this.BackgroundImageLayout;
menuItem.Checked = this.Checked;
menuItem.CheckOnClick = this.CheckOnClick;
menuItem.CheckState = this.CheckState;
menuItem.DisplayStyle = this.DisplayStyle;
menuItem.Dock = this.Dock;
menuItem.DoubleClickEnabled = this.DoubleClickEnabled;
menuItem.Enabled = this.Enabled;
menuItem.Font = this.Font;
menuItem.ForeColor = this.ForeColor;
menuItem.Image = this.Image;
menuItem.ImageAlign = this.ImageAlign;
menuItem.ImageScaling = this.ImageScaling;
menuItem.ImageTransparentColor = this.ImageTransparentColor;
menuItem.Margin = this.Margin;
menuItem.MergeAction = this.MergeAction;
menuItem.MergeIndex = this.MergeIndex;
menuItem.Name = this.Name;
menuItem.Overflow = this.Overflow;
menuItem.Padding = this.Padding;
menuItem.RightToLeft= this.RightToLeft;
menuItem.ShortcutKeys = this.ShortcutKeys;
menuItem.ShowShortcutKeys = this.ShowShortcutKeys;
menuItem.Tag = this.Tag;
menuItem.Text = this.Text;
menuItem.TextAlign = this.TextAlign;
menuItem.TextDirection = this.TextDirection;
menuItem.TextImageRelation = this.TextImageRelation;
menuItem.ToolTipText = this.ToolTipText;
menuItem.Available = menuItem.Available;
if (!AutoSize) {
menuItem.Size = this.Size;
}
return menuItem;
}
Posted by Microsoft on 7/11/2005 at 10:43 AM
Submitted via EggHeadCafe - Software Developer Portal of Choice
BOOK REVIEW: Super SQL Server Systems [Rampant]
http://www.eggheadcafe.com/tutorial...53-b1f2210bece8/book-review-super-sql-se.aspx