I have a TextBox
in my form, the user should enter some string there.
After each 2 characters, it should automatically add a "|"
in there. But I don't know how to do that. Here's my code:
private void textBox1_TextChanged(object sender, EventArgs e)
{
string input = textBox1.Text; int count = 0;
foreach (char c in input)
{
count++;
if (count == 2)
{
input += '|';
count = 0;
textBox1.Text = input;
}
}
}
- The user should only enter the characters in hexadecimals (meaning 0-9, a-f).
I've tried the e.Keychar
on the Keypress
event, but it doesn't work, if the user use Copy-Paste
and Ctrl-C
, Ctrl-V
.
Aucun commentaire:
Enregistrer un commentaire