 |
| C# 2005 For discussion of Visual C# 2005. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

March 21st, 2008, 04:03 PM
|
|
Friend of Wrox
|
|
Join Date: Dec 2006
Posts: 176
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
custom control
hi expert
I Create a class that derived from MenuStrip Class. Then I Overrided the OnPaint Method For Creating My Customize Face For My Menu.
I Create A Class With Deriven Of ToolStripMenuItem and I Override OnPaint too.
Now I want when user adds new Item to myMenu, the AddedItem become Derive Form My Custom ToolStripMenuitem That I Created, not Drive From Originally ToolStripMenuItem Class.
what action I do for this perpose?
|
|

March 21st, 2008, 04:25 PM
|
|
Friend of Wrox
|
|
Join Date: Mar 2007
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
|
|
You should be able to add the derived (your custom) menu items, even though it is asking for a ToolstripMenuItem class, since you have inherited from it. Your CustomToolStripMenuItem IS A ToolStripMenuItem :)
Beauty of inheritance :)
Rob
The Developing Developer
Currently Working Towards: MCAD C#
My Blog: http://www.robzyc.spaces.live.com
<center> "Nothing can stop the man with the right mental attitude from achieving his goal;
nothing on earth can help the man with the wrong mental attitude".
Thomas Jefferson</center>
|
|

March 22nd, 2008, 04:31 AM
|
|
Friend of Wrox
|
|
Join Date: Dec 2006
Posts: 176
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
oooooooooooh
you make mistake,
I said in previouse post, i drived my ToolStripmenuitem From ToolStripMenuItem Class, ok?
now , i want ,when user use My MenuSTrip and he/she add the new Item to myMenu at Design Time, the added Item Become with Driven Of My ToolStipMenuItem Instead of Originally ToolStripManuItem Class.
I hope you understand thing that is in My mind.
good luck
|
|

March 22nd, 2008, 05:43 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2007
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
|
|
OK, here's what I think, but I could be wrong, so open to suggestions myself!
I dont think you will be able to achieve this by overriding the existing " Items" property, this is because you want to change the signature, which you cannot do. You can <s>override</s> hide implementation of derived members using the " new" keyword, however, the member must still share the same signature.
I'm not to sue about adding the design-time support to use your own objects rather than the base ToolStripItems, never done it myself, I may have a play and see what I can figure out.
Other than that, I would say it may be worth overriding the Items method and setting its Browsable attribute to False, thus hiding it from the designer, and instead creating your own property (e.g StripItems) to take items of your MyToolStripItems to the MyToolStrip.
For Example:
Code:
class MyToolStrip : ToolStrip
{
List<ToolStripItem> items = new List<ToolStripItem>();
// Hide the Base Items Property from the Designer, Code Access is Still OK though.
[BrowsableAttribute(false)]
public override ToolStripItemCollection Items
{
get { return base.Items; }
}
// Create the new, browsable property.
[BrowsableAttribute(true),
CategoryAttribute("Data")]
public List<MyToolStripItem> StripItems
{
get
{
// Cast the items to a ToolStripItem List
List<MyToolStripItem> rtn = new List<MyToolStripItem>();
foreach (ToolStripItem item in base.Items)
{
rtn.Add((MyToolStripItem)item);
}
return rtn;
}
}
}
Like I said, I'm sure there is probably a better way of doing this, but would be keen to find out myself!
Hope this helps!
Rob
The Developing Developer
Currently Working Towards: MCAD C#
My Blog: http://www.robzyc.spaces.live.com
<center> "Nothing can stop the man with the right mental attitude from achieving his goal;
nothing on earth can help the man with the wrong mental attitude".
Thomas Jefferson</center>
|
|

March 24th, 2008, 04:22 AM
|
|
Friend of Wrox
|
|
Join Date: Dec 2006
Posts: 176
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
thanx for your reply
i use this code
Code:
public class MyMenuStrip : MenuStrip
{
List<ToolStripItem> items = new List<ToolStripItem>();
#region constructor
public MyMenuStrip()
{
}
#endregion
#region override methods
[System.ComponentModel.Browsable(false)]
public override ToolStripItemCollection Items
{
get
{
return base.Items;
}
}
// Create the new, browsable property.
[BrowsableAttribute(true),
CategoryAttribute("Data")]
public List<MyToolStripItem> StripItems
{
get
{
// Cast the items to a ToolStripItem List
List<MyToolStripItem> rtn = new List<MyToolStripItem>();
foreach (ToolStripItem item in base.Items)
{
rtn.Add((MyToolStripItem)item);
}
return rtn;
}
}
}
but, I cann't use the StripItems property.
when i want use this peoperty in design mode, when i click the ellips button on this property I get the flowing error:
" Unable to cast object of type 'System.Windows.Forms.Design.DesignerToolStripCont rolHost' to type 'System.Windows.Forms.ToolStripMenuItem'."
note : MyToolStripItem is My Customize class that inherites From ToolStripMenuItem
thanx
|
|

March 24th, 2008, 08:56 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2007
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Hi angelboy,
Again, sorry I not of much use here, not done much component development, and even less in-depth design time support!
A quick google of the issue reveals that you do need to do a little extra legwork to add design time support to a custom ToolStrip.
Have a read of this link, may be a good starting point:
http://forums.microsoft.com/MSDN/Sho...48984&SiteID=1
Let me know how you get on, be interested to know how it works myself!
Rob
The Developing Developer
Currently Working Towards: MCAD C#
My Blog: http://www.robzyc.spaces.live.com
<center> "Nothing can stop the man with the right mental attitude from achieving his goal;
nothing on earth can help the man with the wrong mental attitude".
Thomas Jefferson</center>
|
|

March 24th, 2008, 10:31 AM
|
|
Friend of Wrox
|
|
Join Date: Dec 2006
Posts: 176
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
hi Rob,
I check the link but unfortunately it doesn't help me and i didnt get my answer on that link.
if you want,
I can send my all code here.
But already i whould like to thank for your replies
|
|

March 24th, 2008, 12:19 PM
|
|
Friend of Wrox
|
|
Join Date: Mar 2007
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Hi angelboy,
I've re-read the link, and I believe the info you want is in there..
Did you read all the comments, and posted links?
In short, the designer is saying it cannot work with the types that we have given it (the List<MyToolStripItems), but it is intending to work with ToolstripControlHost, logic therefore suggests that you need to create your own version of this, designed to work with your own types.
Again, sorry I cant offer more info as I have not attempted to do this myself, and currently dont have the time to have a go at doing it. Sadly, it looks like no-one else here has either! :(
So, you need to start figuring it out. Often, the answer cannot always be found in code samples, it takes reading, trial, error, error, error, reading, trial, error, error, reading, a cup of cofee, another read, success! :)
Good luck, keep us posted! :)
Rob
The Developing Developer
Currently Working Towards: MCAD C#
My Blog: http://www.robzyc.spaces.live.com
<center> "Nothing can stop the man with the right mental attitude from achieving his goal;
nothing on earth can help the man with the wrong mental attitude".
Thomas Jefferson</center>
|
|

March 24th, 2008, 03:52 PM
|
|
Friend of Wrox
|
|
Join Date: Dec 2006
Posts: 176
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi,
ok, thanx.
I'll read that again carefully
regards
|
|

March 24th, 2008, 04:30 PM
|
|
Friend of Wrox
|
|
Join Date: Mar 2007
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Hi angelboy,
Had a spare 10 minutes earlier so had a quick play. Looks like there may be a fair bit of work involved in doing this! :( Seems everything to do with the ToolStrip is specialised!
Be interested to know how this turns out, please keep me posted, and of course, if you need another geek to bounce thoughts/ideas off, then please ask :)
Rob
The Developing Developer
Currently Working Towards: MCAD C#
My Blog: http://www.robzyc.spaces.live.com
<center> "Nothing can stop the man with the right mental attitude from achieving his goal;
nothing on earth can help the man with the wrong mental attitude".
Thomas Jefferson</center>
|
|
 |