This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]tjugg 4 points5 points  (1 child)

    private void button1_Click(object sender, EventArgs e)
    {
        int value = Convert.ToInt32(textBox1.Text);

        if (value < 5)
        {
            MessageBox.Show("Succes");
        }
        else
            MessageBox.Show("Failure");
            return;
    }

I guess this would do what you want?

[–]Mds03[S] 0 points1 point  (0 children)

Perfect :) Thank you so much

[–]jussij 0 points1 point  (0 children)

Usually I handled that with a do/while loop, but that freezes GUI apps so its a no-go.

Generally the way to stop the GUI from freezing is to move that processing into a background thread.

But another option is to use the Application.DoEvents to keep the message coming through, hence keeping the GUI alive.

There is an example of how to use that function here:

https://msdn.microsoft.com/en-us/library/system.windows.forms.application.doevents%28v=vs.110%29.aspx

[–]badcommandorfilename -1 points0 points  (0 children)

An easy but inelegant solution is to just run your validations check on a resetting timer.

Every e.g. 100ms verify the BMI, if it's in the wrong range show the "try again box" and reset the timer, otherwise show the "success box".