Le réseau pour les développeurs >
Forums - Accueil
>
Visual C# General
>
How to make ToolStripItem.DismissWhenClicked FALSE
How to make ToolStripItem.DismissWhenClicked FALSE
- I want to keep one ToolStripItem of a MenuStrip visible after I click it, how to?
In the document, is seems ToolStripItem.DismissWhenClicked controls this, but it cannot be accessed or set.
Thank you.
Yours, Adun.
Toutes les réponses
- Won't something like this work for you?
class ToolStripItemEx : ToolStripItem { protected override bool DismissWhenClicked { get { return true; } } }
In the get statement you could specify when to be dismissed and when not.
Ionut Will this make the ToolStripItem Visible after I click it?
I want to process the click event, and keep it visible.
Thank you.
- Hi,
You can write this code to CheckedChanged event of ToolStipMenuItem that you want to keep visible after clicked.
Or you can develop your custom ToolStripMenuItemClass like following.private void bToolStripMenuItem_CheckedChanged(object sender, EventArgs e) { ((ToolStripMenuItem)bToolStripMenuItem.OwnerItem).ShowDropDown(); }
public class MyToolStripMenuItem : ToolStripMenuItem { protected override void OnCheckedChanged(EventArgs e) { base.OnCheckedChanged(e); ((ToolStripMenuItem)this.OwnerItem).ShowDropDown(); } }
- Proposé comme réponseHarry ZhuMSFT, Moderatorjeudi 5 novembre 2009 02:22
Thank you, I 'll try in your way later.
In this way, there is one problem,
after I click a 4th level menu item, the item and its parent( a 3rd level menu item) are visible,
while the 2nd level menu item is invisible now.
Shall I call the ShowDropDown method recursively to the root?
- Hi,
You might need to call the method on every ownerItem:
ToolStripMenuItem ts = (ToolStripMenuItem)bToolStripMenuItem.OwnerItem;
while (ts!= null)
{
ts.ShowDropDown();
//Console.WriteLine(ts.Name);
ts = (ToolStripMenuItem)ts.OwnerItem;
}
Harry
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.- Proposé comme réponseHarry ZhuMSFT, Moderatorjeudi 5 novembre 2009 02:22
- Thank you, Harry.
I 'm afraid this method does not work as expected.
- Hi,
Could you please be more specific ? I test it and these items does not disapear after I click one .
Harry
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.

