C# Hello, i have a question. For example, i have a txtBox focused, and im writting text on it, but when i see the key '-' pressed, i want to not show that character in my textbox, and at the same time delete de last character from it. Is there any way to do?
private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
char f = char.Parse("-");
string t = this.textBox1.Text;
if(e.KeyChar == f)
{
// Do not print the char
e.Handled = true;
// Remove the last char
this.textBox1.Text = t.Substring(0, t.Length - 1);
// Set the I-beam at the end of the text box
this.textBox1.Select(this.textBox1.Text.Length, 1);
}
}
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.