Skip to main content

I was at a breakpoint in my managed code program and I was looking at the properties listed for a menu strip.  One of them was "DisplayedItems" with a heart shaped icon beside it.  It is a collection and I can see the items in the collection at the breakpoint.  I would very much like to use the information in this collection in my program but that property is not available to my program.  Why not?  If my menu strip is too wide to see in my window, I would like to increase the width of my window.  This collection would tell me if any of the menu items are not displayed.  



------------------------------
Lee Robinson
Software Development Manager
New Hampshire Admin Office of the Courts
Concord NH US
------------------------------

I was at a breakpoint in my managed code program and I was looking at the properties listed for a menu strip.  One of them was "DisplayedItems" with a heart shaped icon beside it.  It is a collection and I can see the items in the collection at the breakpoint.  I would very much like to use the information in this collection in my program but that property is not available to my program.  Why not?  If my menu strip is too wide to see in my window, I would like to increase the width of my window.  This collection would tell me if any of the menu items are not displayed.  



------------------------------
Lee Robinson
Software Development Manager
New Hampshire Admin Office of the Courts
Concord NH US
------------------------------

Hi Lee,

This appears to be a Private property which means you need to access it through Reflection.

Add $set ilusing"System.Reflection" to the top of your program and do something like the following:

    declare mytype as type Type = type of System.Windows.Forms.ToolStrip
    declare propInfo as type PropertyInfo = mytype::GetProperty("DisplayedItems", type BindingFlags::NonPublic b-or type BindingFlags::Instance)
    declare myDisplayedItems = propInfo::GetValue(toolStrip1) as type ToolStripItemCollection
    declare myDisplayCount = myDisplayedItems::Count



------------------------------
Chris Glazier
Principal Technical Support Specialist
Rocket Forum Shared Account
------------------------------

Hi Lee,

This appears to be a Private property which means you need to access it through Reflection.

Add $set ilusing"System.Reflection" to the top of your program and do something like the following:

    declare mytype as type Type = type of System.Windows.Forms.ToolStrip
    declare propInfo as type PropertyInfo = mytype::GetProperty("DisplayedItems", type BindingFlags::NonPublic b-or type BindingFlags::Instance)
    declare myDisplayedItems = propInfo::GetValue(toolStrip1) as type ToolStripItemCollection
    declare myDisplayCount = myDisplayedItems::Count



------------------------------
Chris Glazier
Principal Technical Support Specialist
Rocket Forum Shared Account
------------------------------

It works beautifully!  Thank you, Chris.  That must have taken some digging.  I appreciate your efforts on this.



------------------------------
Lee Robinson
Software Development Manager
New Hampshire Admin Office of the Courts
Concord NH US
------------------------------

It works beautifully!  Thank you, Chris.  That must have taken some digging.  I appreciate your efforts on this.



------------------------------
Lee Robinson
Software Development Manager
New Hampshire Admin Office of the Courts
Concord NH US
------------------------------

Lee,

Although Chris's suggestion will allow you to get the item I would strongly advise against using private/internal properties obtained via reflection, as there is probably a reason why they are not accessible, and that you try to find a different way of determining how to resize your window. 



------------------------------
Gael Wilson
Lead Software Engineer
Rocket Forum Shared Account
Newbury United Kingdom
------------------------------

Lee,

Although Chris's suggestion will allow you to get the item I would strongly advise against using private/internal properties obtained via reflection, as there is probably a reason why they are not accessible, and that you try to find a different way of determining how to resize your window. 



------------------------------
Gael Wilson
Lead Software Engineer
Rocket Forum Shared Account
Newbury United Kingdom
------------------------------

I welcome any suggestions.



------------------------------
Lee Robinson
Software Development Manager
New Hampshire Admin Office of the Courts
Concord NH US
------------------------------

I welcome any suggestions.



------------------------------
Lee Robinson
Software Development Manager
New Hampshire Admin Office of the Courts
Concord NH US
------------------------------

Perhaps something like this?

 declare ws-count as binary-long = 0
 perform varying ti as type ToolStripItem thru toolStrip1::Items
     if ti::IsOnOverflow
         add 1 to ws-count
     end-if
 end-perform



------------------------------
Chris Glazier
Principal Technical Support Specialist
Rocket Forum Shared Account
------------------------------