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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T10:30:20+00:00 2026-05-21T10:30:20+00:00

I have a multiline textbox which shouldn’t accept alphabets, numbers, newline(enter key) and backspace.

  • 0

I have a multiline textbox which shouldn’t accept alphabets, numbers, newline(enter key) and backspace. In short, the textbox.Text shouldn’t be editable. But I do want the textbox to accept two shortcut keys – control and control+R. One way I can make the textbox un-editable is by making it read-only. But then the textbox wont accept any keystroke at all. In short, my shortcuts ( control and control+R) wont work( Control + R) with read-only method.

Can anyone help in this regard. That’s all I have to do.

One thing I could do here is not to make the textbox read-only and then restrict the characters(alphabets and digits) that could be inputted in the textbox. With this code:

    private void txtResult_KeyPress(object sender, KeyPressEventArgs e)
    {
        // only modifier keys, escape, enter, backspace etc is accepted now
        e.Handled = !char.IsControl(e.KeyChar);
    }

    private void txtResult_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.Control == true)
        {
            if (e.KeyCode == Keys.R)
            {
                // do something
            }
            else
            {
                //do something
            }
        }

        if (e.KeyCode == Keys.Escape)
        {
            //do something
        }
    }

With this technique I can get the shortcuts(control and control+R) working. But the trouble with this method is that Enter and Backspace keys work as well making it possible to edit the text of textbox. How can I specifically restrict Enter and Backspace key being registered from the textbox, but let Control and Escape??

  • 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-21T10:30:21+00:00Added an answer on May 21, 2026 at 10:30 am

    did you try SuppressKeyPress = true ?

    private void textBox2_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.Control == true)
                {
                    if (e.KeyCode == Keys.R)
                    {
                        // do something
                    }
                    else
                    {
                        //do something
                    }
                }
                else
                    e.SuppressKeyPress = true;
    
    
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form field in Drupal which I need some help with. The
I have a menu the have rectangular boxes 90x50. Some have single line text,
I have a TextField with multiline and word wrap enabled, and a fixed width.
I have a String with multiline content and want to select a multiline region,
In WPF, when a user gets focus in a TextBox , I would like
I have a form where one of the fields would allow entry of HTML
I have a webform with a a couple of boundfields in an edit window
I am writing text to a multi-line text box using data from the serial
Let's say I have a page using the Validation Plugin more or less as
I'm working on an GUI program, and I use AppendText to update status in

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.