C# – waiting for user input on a form


I am currently making an agenda which should be controlled via a seperate input form.

On this form I need to wait for user input before I can move the next input field.

Below is the entry for the to do field for adding a task.
After that it also has fields for date, time and reminders.

private void btn_Say_Click(object sender, EventArgs e)
    string text = tbx_Say.Text;

    if(text.Contains("Add") || text.Contains("add"))
       if(text.Contains("Task") || text.Contains("task"))
            while(screen.task.tb_TaskToDo.Text == "")
                tbx_Anne.Text = "What should happen?";

the perform click starts up a new which needs to be filled through the input form.
with or without the Thread.Sleep(1000) this form will not fully show and it waits for user input which I can not give…

Best Solution

This looks very much like the wrong way to be doing this. I would suggest

  1. Create a form that pops up with a disabled OK button and an enabled Cancel button
  2. Make all the controls bar the first one disabled.
  3. Add an event on the text changing, on the first text box to enable the next control (doing appropriate validation).
  4. Repeat step 3 for all of your controls.

Do not introduce Thread.Sleep in your UI code, this will cause the form to lock up and stop responding.

Related Question