Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9122397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:05:42+00:00 2026-06-17T06:05:42+00:00

When a ContextMenuStrip is opened, if the user types the first letter of a

  • 0

When a ContextMenuStrip is opened, if the user types the first letter of a possible selection – it’s as if he clicked on it. I want to intercept that and get the character that he clicked.

The following code does that, but with hard-coding the possible character. I want a generic way to do this, either by disabling the automatic selection by key stroke (leaving only the mouse clicks) or some way to intercept the character.

The following simplified code assumes I want to have a winform’s Text to be the character typed, and the ContextMenuStrip has one option which is “A”.

public Form1()
{
    InitializeComponent();
    contextMenuStrip1.KeyDown += contextMenuStrip1_KeyDown;
}

private void button1_Click(object sender, EventArgs e)
{
    contextMenuStrip1.Show();
}

void contextMenuStrip1_KeyDown(object sender, KeyEventArgs e)
{
    e.SuppressKeyPress = true;
    if (e.KeyCode == Keys.A)
    {
        if (e.Shift) Text = "A";
        else Text = "a";
    }
}

Using the KeyPress event and checking e.KeyChar doesn’t work because it doesn’t get fired. (the “A” click-event gets fired instead.)

Using one of these: e.KeyCode, e.KeyData, or e.KeyValue doesn’t work (without further hard-coding) because they accept a Shift as a Key.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T06:05:43+00:00Added an answer on June 17, 2026 at 6:05 am

    As noted in the comment, you have to derive your own class from ContextMenuStrip so you can override the ProcessMnemonic() method.

    Annotating this a bit, keyboard processing is very convoluted in Winforms. Shortcut keystrokes are processed very early, before they are dispatched to the control with the focus. Necessarily so, you would not want to implement the KeyDown event for every control so that you could make a shortcut keystroke work.

    This works from the outside in and involves several protected methods, ProcessCmdKey, ProcessDialogChar and ProcessMnemonic. As well as OnKeyDown if the form’s KeyPreview property is set, a VB6 compat feature. So the form gets a shot at it first, then it iterates controls from there, going from container to child controls.

    The ToolStrip class (a base class for ContextMenuStrip) overrides the ProcessMnemonic() method to recognize key presses, mapping them to menu items. So in order to intercept this default processing, you have to override ProcessMnemonic() yourself to get a shot at the key press first.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to leave a ContextMenuStrip open after a selection/check of certain items?
I have a ContextMenuStrip (ctMenuMassEdit) that I want to display when left-clicking a button
Is there an event that fires in vb.net just before a contextMenuStrip appears when
In vb.net (2008), I want to be able to control when a contextMenuStrip (context
I added a ContextMenuStrip to my Form but nowhere in that form (that otherwise
I want to set different ContextMenuStrip for DataGridView Cells , RowHeaders and ColumnHeaders .
I have a winforms ContextMenuStrip that has ToolTipText set for all of it's ToolStripMenuItem's.
I have a ContextMenuStrip that is assigned to several different listboxes. I am trying
I have standard datagridview and I have contextmenustrip. My problem is that I need
i want to replace the current word under mouse cursor while user click on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.