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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:03:26+00:00 2026-05-26T16:03:26+00:00

I have a textbox on a form and a button on the same form.

  • 0

I have a textbox on a form and a button on the same form. On the button click event I want to insist that the textbox has a value in the form of a Double. What I have so far is this –

 public double getUnitStake(Form frontpage)
    {

        double doubleresult=0;
        bool unitStake;

        foreach (Control c in frontpage.Controls)
        {
            if (c.Name == "tbUnitStake")
            {

                unitStake = double.TryParse( (c as TextBox).Text, out doubleresult);
                if (!unitStake)
                {

                }
                else
                {
                    doubleresult=double.Parse((c as TextBox).Text);

                }



            }
        }


        return doubleresult;
    }

But for the life of me I can’t figure out what to do if the double.tryparse method is false. What I want is the program execution to halt until a suitable value has been entered into the textbox. How can I achieve that please? Thanks for all and any help.

  • 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-26T16:03:26+00:00Added an answer on May 26, 2026 at 4:03 pm

    It seems to me you are validating the contents of a textbox. Therefore you can use the validating event of a TextBox Control. Optionally connect an errorProvider control to it to give special focus on the error (blinking exclamation mark). The “e.Cancel” statement will prevent you from doing anything else with your form until a double is entered.

       private void textBox1_Validating(object sender, CancelEventArgs e)
        {
            double doubleresult = 0;
    
            bool result = Double.TryParse(textBox1.Text, out doubleresult);
    
            if (result)
            {
                errorProvider1.SetError(textBox1, string.Empty);
            }
            else
            {
                errorProvider1.SetError(textBox1, "Must be a Double");
                e.Cancel = true;
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

suppose i have label and button on textbox and i want that if i
I have a form with a textbox and a button. IE is the only
I have a dropdownlist and a textbox with a button on a form. When
I have a TextBox control on my Form. I use the Leave event on
C# question: I have a textBox in a default form Form1 and I want
I have a Form with TextBox on it like this: Form f = new
I have to add a textbox inside a form that is composed of a
I have a button on a XAML form that calls the btnName_Click() code in
Can anyone help? I have a change event on a textbox and a click
So I have an input form that I want to use to update 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.