Add a clone property to the ToolStripMenuItem?

A

AAaron123

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.
 
A

AAaron123

I forgot to insert the code.
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.
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
 
P

Psy Technic

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
 
P

Psy Technic

Whoops. a few errors in that. Let me rewrite and get back to you.



Psy Technic wrote:

A Crude Clone
03-Jan-10

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.

Previous Posts In This Thread:


Submitted via EggHeadCafe - Software Developer Portal of Choice
3D Effects Like EggHeadCafe.com
http://www.eggheadcafe.com/tutorial...3-5a677597cbff/3d-effects-like-eggheadca.aspx
 
J

Jeff Johnson

Whoops. a few errors in that. Let me rewrite and get back to you.

No, DON'T get back to him. The question you responded to was from April of
2008. Don't resurrect dead threads.
 
W

wannabe geek

Jeff Johnson said:
No, DON'T get back to him. The question you responded to was from April of
2008. Don't resurrect dead threads.
If somebody in later years has the same problem, he could search for a
question related to his problem, and find an answer here. If you have an
answer, post it. You could make someone's day.
 
A

Arne Vajhøj

If somebody in later years has the same problem, he could search for a
question related to his problem, and find an answer here. If you have an
answer, post it. You could make someone's day.

That is a very relevant point.

Old usenet posts are often good google hits when searching for
solutions to problems.

But the chance of the answer actually being good, if the poster has
not noticed the age of what he is replying to is somewhat below
normal though.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top