简体   繁体   中英

How to override textbox context menu with parent control's context menu?

I have a Panel with various child controls on it. I assigned a context menu to the Panel and it comes up whether I right click on the Panel or on the controls... except for the TextBox control because it comes with its own built in context menu.

I would rather not have to set the context menu on controls directly because they are dynamically generated, and they are generated in a dll outside of the GUI that I'm using them on. Is there any way I can force the Panel's context menu to come up instead of the TextBox's context menu without having to set the ContextMenuStrip property directly on the TextBox?

There isn't a work-around for without having to set the ContextMenuStrip property directly on the TextBox :

Simply assign it.

textBox1.ContextMenuStrip = panel1.ContextMenuStrip;

or

textBox1.ContextMenuStrip = textBox1.Parent.ContextMenuStrip;

You can alternatively loop through the child controls of the panel and assign the menu strip to each child control.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM