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

  • Home
  • SEARCH
  • 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 6188029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:09:34+00:00 2026-05-24T02:09:34+00:00

I have a textbox.In that I have to allow the user to type some

  • 0

I have a textbox.In that I have to allow the user to type some thing in that textbox and i also restrict the user not to select the typed text in that textbox.I have need not to allow the white space at the start of the text box and also i have need not allow the user to type more that 32 characters.Thsi is my code.

    private void txtApplication_Title_KeyPress(object sender, KeyPressEventArgs e)
    {
        txtApplication_Title.Text = txtApplication_Title.Text.Remove(txtApplication_Title.SelectionStart, txtApplication_Title.SelectionLength);
        if (txtApplication_Title.Text.Length== 0)
        {
            e.Handled = (e.KeyChar == (char)Keys.Space);


        }
        int count_charac = txtApplication_Title.Text.Length + 1 ;
        if (count_charac > 32)
        {
            lblApplication_name.Text = data_variables.RES_TXT_STRING_EXCEEDING_APPLICATION_NAME;


            timer1.Interval = 7000;

            timer1.Enabled = true;

            timer1.Tick += new System.EventHandler(OnTimerEvent_Application_name);

        }

    }
    public void OnTimerEvent_Application_name(object sender, EventArgs e)
    {

            lblApplication_name.Text = " ";


 timer1.Dispose();
    }

Here in this code.I am able to restrict the user to 32 characters.And i try to press space at the start it does not allow me.It allows the selection of text using Shift+Arrow key.
I do know how to block the selection.Another thing is suppose I try
Hello and I select Hell and pressing the space directly it starts allowing the space in the text box.Can any one help me.Thanks in advance

  • 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-24T02:09:36+00:00Added an answer on May 24, 2026 at 2:09 am

    Instead of KeyPress event, maybe use the textchanged event.

    Text box has a max length attribute. Also, just call TextBox.Text=TextBox.Text.TrimStart() will remove any whitespace at beginning

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

Sidebar

Related Questions

I have a text box that will allow the user to enter multiple authors
I have a textbox in my WinForm. The user types text (anything that their
In my website I have a textbox that allow user to enter a group
I have a program that allows a user to type JavaScript in a textbox,
I have a TextBox that has the TextChanged event set declaratively. In some cases,
Hi I have a textbox that takes a username input. When the user submits
I would like to have a TextBox that supports AutoComplete and lets users type
Not sure if anyone has experience this issue. I have a TextBox that I
I have a form with some fields of type text and 2 fields (name
I have a program that allows a user to type java code into a

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.