C Sharp
C#, TEXTBOX 숫자만 입력받기
바나나만두
2015. 4. 4. 03:07
반응형
C#, TEXTBOX 숫자만 입력받기
private void textBox1_TextChanged(object sender, EventArgs e)
{
TextBox textBox = sender as TextBox;
Int32 selectionStart = textBox.SelectionStart;
Int32 selectionLength = textBox.SelectionLength;
String newText = String.Empty;
foreach (Char c in textBox.Text.ToCharArray())
{
if (Char.IsDigit(c) || Char.IsControl(c)) newText += c;
}
textBox.Text = newText;
textBox.SelectionStart = selectionStart <=
textBox.Text.Length ? selectionStart : textBox.Text.Length;
}
반응형