-2

How can I make a TextArea that accepts only the words I have already set with C# on Visual studio.

I'm a beginner in programming.


update:

what (-3) about? like I said I'm a beginner, trying to build android game with c#. until now just do some mistakes.

this website little complex to handle with but I will get used to it :) and my english poor

thank you all.

green zone
  • 21
  • 4

1 Answers1

0

Use TextBox and add TextChanged event on your tool

private void textBox1_TextChanged(object sender, EventArgs e)
{
    if (!System.Text.RegularExpressions.Regex.IsMatch(textBox1.Text, "^[a-zA-Z]"))
    {
        MessageBox.Show("This textbox accepts only alphabetical characters");
        textBox1.Text.Remove(textBox1.Text.Length - 1);
    }
}

More Info

textBox1.TextChanged += new TextChangedEventHandler(textBox1_TextChanged);
private void textBox1_TextChanged(object sender, EventArgs e)
{
    Regex regex = new Regex(@"[^0-9^+^\-^\/^\*^\(^\)]");
    MatchCollection matches = regex.Matches(textBox1.Text);
    if (matches.Count > 0) {
       //tell the user
    }
}

private void textBox1_TextChanged(object sender, EventArgs e)
    {
        string yourWord = "mouse";
        if (textBox1_Text.Text.Contains(yourWord))
        {
            textBox1_Text.Text.Replace(yourWord, "");
        }
    }
Metin Atalay
  • 1,375
  • 18
  • 28