473,396 Members | 1,936 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Need quick help...

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?
Nov 16 '05 #1
4 1312
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*R SS*

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...aspx?FeedId=41

*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*R SS*

"Jacek Jurkowski" <jj********@datacomp.szczecin.pl> wrote in message
news:ep**************@TK2MSFTNGP10.phx.gbl...
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?

Nov 16 '05 #2
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.

Nov 16 '05 #3

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*R SS*

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...aspx?FeedId=41

*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*RSS*R SS*

""Peter Huang"" <v-******@online.microsoft.com> wrote in message
news:m8**************@cpmsftngxa10.phx.gbl...
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.

Nov 16 '05 #4
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.

Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: netpurpose | last post by:
I need to extract data from this table to find the lowest prices of each product as of today. The product will be listed/grouped by the name only, discarding the product code - I use...
41
by: Psykarrd | last post by:
I am trying to declare a string variable as an array of char's. the code looks like this. char name; then when i try to use the variable it dosn't work, however i am not sure you can use it...
8
by: Dutchy | last post by:
Dear reader, In an attempt to obtain the path to the quick-launch-folder in order to create a shortcut to my application-updates during installation , I thought to: 1- check if quick launch...
1
by: aredo3604gif | last post by:
On Sun, 10 Apr 2005 19:46:32 GMT, aredo3604gif@yahoo.com wrote: >The user can dynamically enter and change the rule connection between >objects. The rule is a "<" and so given two objects: >a <...
0
by: U S Contractors Offering Service A Non-profit | last post by:
Brilliant technology helping those most in need Inbox Reply U S Contractors Offering Service A Non-profit show details 10:37 pm (1 hour ago) Brilliant technology helping those most in need ...
1
by: drewhiggins | last post by:
Hi, I would like to ask for some help for a login form. To access some downloads on the server (I can only use JS and HTML), I have a login form. But how can I make a box that gets the browser to...
1
by: AngelLopez1989 | last post by:
I need the complete C++ program/ algorithm of Quick Sort. Can you please help me out? No pseudocode please. Can you please also explain how to do the quick sort? Thank you!
1
by: bartman1973 | last post by:
Hi guys and gals, i am new in C++ and would like to seek some help. I just transfered to this new department and now they are asking me to do some programming. I am just in the process of...
1
by: Joseph Geretz | last post by:
I'm noticing that when my DataGrid has focus, it handles the Enter key by advancing to the next row in the grid. This neutralizes Forms's current defined AcceptButton. My primary question: is...
2
by: yela | last post by:
I am working in a floting menu for a website, I found this cool script, it works great, but I need to limit the movement of the menu to a table area, right now it goes up and down through the whole...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.