Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 366
  • Last Modified:

c# inform wait for input value

Console.WriteLine("Enter month no ");
                string user_input = Console.ReadLine();

How can i do in winform have a box  wait for user in put and then keep it value as variable

and how can i force it much be number from 1 to 12
0
teera
Asked:
teera
  • 3
2 Solutions
 
exceterCommented:
If you use TextBox, then do it in TextChanged event.
0
 
teeraAuthor Commented:
Hi exceter

can you show me some code just for example
0
 
exceterCommented:
1. You want do something as soon as user inputs into textbox, or as he hits Button?

2. For numbers only textbox use the KeyPress event
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
    if (!char.IsControl(e.KeyChar) 
        && !char.IsDigit(e.KeyChar) 
        && e.KeyChar != '.')
    {
        e.Handled = true;
    }

    // only allow one decimal point
    if (e.KeyChar == '.' 
        && (sender as TextBox).Text.IndexOf('.') > -1)
    {
        e.Handled = true;
    }
}

Open in new window

0
 
exceterCommented:
1. for Button click
private void button1_Click(object sender, EventArgs e)
{
    string tmp = textBox1.Text;
    .....
}

Open in new window

0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
If you want to wait for a user entry then display a custom form with OK and Cancel buttons via ShowDialog().  Place a NumericUpDown control on the custom form to obtain a value between 1 and 12.
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now