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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:41:15+00:00 2026-05-24T16:41:15+00:00

This simple problem reoccurs many times for me in .NET with WinForms. I have

  • 0

This simple problem reoccurs many times for me in .NET with WinForms. I have a textbox and would like to treat the Enter key as the same as the Tab key, as in whenever I press enter, I want lostfocus to be raised, the next control to be Focused, etc. I have noticed many similar questions to this, and I can solve the problem by capturing the KeyDown and when Enter is detected to move the focus, but what I am looking for is a best practice and if not for insight on where the Textbox control detects the Tab key internally and how it does it’s thing so I can just add an “|| key == Keys.Enter”. This would stop Keydown from being raised and instead move focus to the next control and raise other appropriate messages.

I checked this similar question before
.NET TextBox – Handling the Enter Key but it isn’t what I really want to accomplish. What i really want to do is to as early as possible interpret ENTER as TAB in the Textbox control or intercept and change the Enter to a Tab and let the Textbox do it’s thing.

Edit: Here’s something along the lines of what I’m looking for, but I’m not sure the “safety” of modifying the Windows message like this…

class FancyTextBox : TextBox
{
    public bool TreatEnterAsTab { get; set; }
    const int WM_KEYDOWN = 0x100;
    const int KEY_TAB= 9;
    const int KEY_ENTER = 13;

    public override bool PreProcessMessage(ref Message msg)
    {
        if (TreatEnterAsTab && msg.Msg == WM_KEYDOWN && msg.WParam.ToInt32() == KEY_ENTER)
            msg.WParam = new IntPtr(KEY_TAB);

        return base.PreProcessMessage(ref msg);
    }
}
  • 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-05-24T16:41:16+00:00Added an answer on May 24, 2026 at 4:41 pm

    This is fine. Just a few details, you don’t want to do it if the text box is multiline or when the Shift, Alt or Ctrl key is down. Turn it on by default, that’s why you’re using it:

    using System;
    using System.ComponentModel;
    using System.Windows.Forms;
    
    class FancyTextBox : TextBox {
        public FancyTextBox() {
            TreatEnterAsTab = true;
        }
        [DefaultValue(true)]
        public bool TreatEnterAsTab { get; set; }
    
        public override bool PreProcessMessage(ref Message msg) {
            if (TreatEnterAsTab && (!this.Multiline || this.AcceptsReturn) && 
                Control.ModifierKeys == Keys.None && 
                msg.Msg == WM_KEYDOWN && (Keys)msg.WParam.ToInt32() == Keys.Enter) {
                  msg.WParam = (IntPtr)Keys.Tab;
            }
            return base.PreProcessMessage(ref msg);
        }
        private const int WM_KEYDOWN = 0x100;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This seems like a very simple and a very common problem. The simplest example
I have this simple problem. I'll try to explain with a sample code An
I have searched the site for this simple problem but cant find an answer.
I have this simple problem that gets an input from the user using a
I have a simple problem, yet i am unable to solve this. Either my
Seems like a simple problem, but can't get this to work. In the example
file = [file1,file2,...].join( ) `paste #{file}` Hello, I have this simple problem that has
i'm a total newbie to java and Alfresco and i have this simple problem:
This may be a very simple problem, but I couldn't find an answer googleing
I am sure this is a very simple problem, but I am new to

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.