How can I treat a form with textbox as input box

  • Thread starter Thread starter pei_world
  • Start date Start date
P

pei_world

I created a form with textbox components.
How can I control the main program thread wait for user input?
once user click "OK" in my input form, then set all variables and return
back to my main thread.

thanks
 
Here's a bit of code:

On a Form (InputBox.cs) which contains a textbox (textBox1) and two buttons
(button1 and button2). Drop this in as the constructor:

public InputBox()
{
InitializeComponent();
button1.Text = "OK";
button1.DialogResult = DialogResult.OK;
button2.Text = "Cancel";
button2.DialogResult = DialogResult.Cancel;
textBox1.Text = "";
}
public InputBox(string Caption, string DefaultValue) : this()
{
this.Text = Caption;
textBox1.Text = DefaultValue;
}

// and an accessor to get the value
public string Value
{
get { return textBox1.Text; }
}

Now call the thing like this... (from the main thread - a button click on
the main form in my case)

private void button1_Click(object sender, System.EventArgs e)
{
InputBox input = new InputBox("Enter your zip code", "85048");
if (input.ShowDialog() == DialogResult.OK)
MessageBox.Show(input.Value);
input.Dispose();
}


HTH;
Eric Cadwell
http://www.origincontrols.com
 
Back
Top