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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:49:25+00:00 2026-06-11T09:49:25+00:00

May be My Question is not seems like a good one but here is

  • 0

May be My Question is not seems like a good one but here is the Description:
I am creating an application in this in a form i have a textbox which is taking input from user here is my Code

private void Form1_Load(object sender, EventArgs e)
{
    textBox1.Text = string.Format("{0:0.##}", "0.00");
}

this will show value in textbox at pageload:0.00
Now after this if i click on backspace button of keyboard then

if (e.KeyChar.ToString() == ".")
{
    e.Handled = true;
    int b = textBox1.Text.LastIndexOf("00");
    textBox1.SelectionStart = b;
}
else
{
    string abc = "0";
    string a = textBox1.Text.TrimStart(abc.ToCharArray());
    textBox1.Text = a;
}

this code will lead me to here the textbox has now: .00 only
but after this when i enter some value then it will take values as;
2334.3423424
but i want to do like
2334.34
it means value should replace .00 only and user cant enter value after that.

  • 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-11T09:49:26+00:00Added an answer on June 11, 2026 at 9:49 am

    This piece of code will restrict your user in entering only 2 digits after the decimal in your textbox.

        //In key press event:
        if (e.KeyChar == '.' && (sender as TextBox).Text.IndexOf('.') > -1)
        {
            e.Handled = true;
        }
        if (!char.IsControl(e.KeyChar))
        {
            TextBox tt = (TextBox)sender;
            if (tt.Text.IndexOf('.') > -1 && tt.Text.Substring(tt.Text.IndexOf('.')).Length >= 3)
             {
               e.Handled = true;
             }
         }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This may seem a basic question but my is not currently working. I am
This may seem an easy question, but not to me, also a search has
This question may not directly relate to programming. I have noticed that the technology
I concede that this question may fall into the 'discussable' but not 'answerable' category.
This may not be a programming question, but I don't know where to ask
I know this question may have appeared few times here and in the internet.
My question may be quite similar to others, but not the same. In the
(note that this question is not about CAS, it's about the May fail spuriously
I think my question may be a duplicate, but I do not know what
First of all I am not a designer. so this question is may be

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.