Ivan
Ivan

Reputation: 31

The comma in the textBox

I would like your help for this problem: when I create a textbox and type "." the point, I would like it to come out "," the comma. I've already tried using textBox.Text.Replace but it does not work. More suggestions? Thank you in advance.

protected void TextBox1_TextChanged(object sender, EventArgs e)  
{  
if (TextBox1_Tex.Contains("."))
{
  TextBox1_Tex.Replace(".", ",");
}  

Not Work!

Upvotes: 2

Views: 276

Answers (2)

Vlad C
Vlad C

Reputation: 445

private void TextBox1_TextChanged(object sender, EventArgs e)
{
    TextBox textBox = (TextBox)sender;
    textBox.Text = textBox.Text.Replace(".", ",");
    textBox.SelectionStart = textBox.Text.Length;
}

Upvotes: 2

Ivan
Ivan

Reputation: 31

this code Work perfect and is very fast !! Thanks to much to every body and to you @ethvlad

private void TextBox1_TextChanged(object sender, EventArgs e)
{
    TextBox textBox = ((TextBox)sender);
    textBox.Text = textBox.Text.Replace(".", ",");
    textBox.SelectionStart = textBox.Text.Length;
}

Upvotes: 0

Related Questions