Need quick help...

  • Thread starter Thread starter Jacek Jurkowski
  • Start date Start date
J

Jacek Jurkowski

I have to add a property to an object that is already
allive. The problem is that I'm creating MainMenu
from a definition file ... enyway , there is a need to add
each menu item some extra informations. I used to
do that using Tag property of an objects but ManuItem
doesn't have anything like that. So how to add a Tag property
to a MenuItem?
 
Try using a Hashtable to associate the menu item object as a key with some
data that you define.

--
Bob Powell [MVP]
Visual C#, System.Drawing

All you ever wanted to know about ListView custom drawing is in Well Formed.
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*

The GDI+ FAQ: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://royo.is-a-geek.com/siteFeeder/GetFeed.aspx?FeedId=41

*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*
 
Hi Jacek,

First of all, I would like to confirm my understanding of your issue.
From your description, I understand that you wants to add extra information
to a menuitem by using Tag Property which the menutiem does no have.
Have I fully understood you? If there is anything I misunderstood, please
feel free to let me know.

I think we can create a new class derived from MenuItem and add a Tag
proterty to the class.

public class MyMenuItem : MenuItem
{
object _Tag;
public object Tag
{
get
{
return _Tag;
}
set
{
_Tag = value;
}
}
}

private void Form1_Load(object sender, System.EventArgs e)
{
MainMenu menu = new MainMenu();
this.Menu= menu;
MyMenuItem menuItem1 = new MyMenuItem();
menuItem1.Text="hello";
menuItem1.Tag="fsdf";
menuItem1.Click+=new EventHandler(menuItem1_Click);
menu.MenuItems.Add(menuItem1);
}

private void menuItem1_Click(object sender, EventArgs e)
{
MessageBox.Show("menuItem1.Tag: " + (this.Menu.MenuItems[0] as
MyMenuItem).Tag.ToString());
}


Please apply my suggestion above and let me know if it helps resolve your
problem.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
This soloution is valid but the trouble with doing this is that the derived
class cannot be used at design time.

--
Bob Powell [MVP]
Visual C#, System.Drawing

All you ever wanted to know about ListView custom drawing is in Well Formed.
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*

The GDI+ FAQ: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://royo.is-a-geek.com/siteFeeder/GetFeed.aspx?FeedId=41

*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*
 
Hi Jacek,

As Bob said, if you wants to do the job in design time, I think you can
adopt Bob's suggestion.
If you still have any concern on this issue, please feel free to post here.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 

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

Back
Top