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 8437073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:20:12+00:00 2026-06-10T07:20:12+00:00

Currently, I’m overriding the Form.ProcessDialogKey method inside my WinForms form to allow the user

  • 0

Currently, I’m overriding the Form.ProcessDialogKey method inside my WinForms form to allow the user to directly select a tab page of a tab control inside the form when pressing Alt+1 … Alt+9.

I.e. pressing Alt+1 should select the first tab, Alt+2 the second tab, etc.

This is an excerpt of my code:

protected override bool ProcessDialogKey(Keys keyData)
{
    if ((e.KeyData & Keys.Alt) == Keys.Alt)
    {
       if ((e.KeyData & Keys.D1) == Keys.D1) tabIndex = 0;
       else if ((e.KeyData & Keys.D1) == Keys.D1) tabIndex = 0;
       else if ((e.KeyData & Keys.D2) == Keys.D2) tabIndex = 1;
       else if ((e.KeyData & Keys.D3) == Keys.D3) tabIndex = 2;
       // ...
    }
}

I discovered that my check give redundant results. E.g. when pressing Alt+3,

(e.KeyData & Keys.D3) == Keys.D3 // <<== TRUE.

is true, but also other checks are true, e.g.:

(e.KeyData & Keys.D1) == Keys.D1 // <<== also TRUE.
(e.KeyData & Keys.D0) == Keys.D0 // <<== also TRUE.

I do think this is quite logical, since the Keys enumeration does lot of bitwise combination of other Keys member values.

So I do unsertand why I get too much true results, I just do not know how to do a correct check.

My question:

Can I use the Form.ProcessDialogKey method at all to check for Alt+1…Alt+9 combination or should I choose another aproach?

(If there is another aproach, I would love to get a link to it)

Update 1:

It seems that if I revers the check order, i.e. first Keys.D9 and then down to Keys.D1 that the matching works better (correct?)

  • 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-10T07:20:14+00:00Added an answer on June 10, 2026 at 7:20 am

    Using the & operator here is not correct. The Keys enumeration has the [Flags] attribute but it is a combination of flags and a value. Necessarily so, there are many more keys than bits in an int or long. Some bits indicate a modifier, like Keys.Alt, but the lower 16 bits are the key code and you need to use the == operator to compare it.

    Consider this code to keep it DRY:

        protected override bool ProcessDialogKey(Keys keyData) {
            if (keyData >= (Keys.Alt | Keys.D1) && keyData <= (Keys.Alt | Keys.D9)) {
                int cmd = (keyData & Keys.KeyCode) - Keys.D0;
                // etc...
                return true;
            }
            return base.ProcessDialogKey(keyData);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently when the user presses tab in the qty text box it does not
Currently I am using HTML files for parts of my user interface. I display
Currently, most of the popular websites, like google, yahoo detect if the user connection
Currently I have the following Mapping in my Controller: @RequestMapping( value = /add.html, method
Currently, I use an abstract factory to allow the specification of a custom class
Currently i am consuming web service from android by the method SOAP.Here i need
Currently, Django 1.2.3 User model unicode is def __unicode__(self): return self.username and I'd like
Currently, db4o does not allow indexing on the contents of collections. What object databases
Currently, I don't really have a good method of debugging JavaScript in Internet Explorer and
currently I have following code: home.php <form name='myformname' id='myformid'> <input type='text' name='mytext1' value='abc'> <input

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.