Quantcast
Channel: User Sinatr - Stack Overflow
Viewing all articles
Browse latest Browse all 609

Answer by Sinatr for How to disable TAB key in ContextMenuStrip?

$
0
0

To disable Tab-key in menus you need to handle PreviewKeyDown and set e.IsInputKey, this seems to prevent selection logic from running.

There is a problem with sub-menus, because each drop-down has its own event, which you need to handle.

If menu is created, then you can find all sub-menus recusively and subscribe each, something like this:

public Form1(){    InitializeComponent();    DisableTabKeyRecursive(contextMenuStrip1);    void DisableTabKeyRecursive(ToolStripDropDown menu)    {        menu.PreviewKeyDown += (s, e) =>        {            if (e.KeyCode == Keys.Tab)                e.IsInputKey = true;        };        foreach (ToolStripMenuItem item in menu.Items)            if (item.HasDropDown)                DisableTabKeyRecursive(item.DropDown);    }}

Viewing all articles
Browse latest Browse all 609

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>