Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- VS Code
- JSON
- label
- Python
- paramiko
- pytorch
- nvidia-smi
- 채보
- error
- SSH
- Docker
- ubuntu
- C++
- OpenCV
- windows forms
- 컨테이너
- 오류
- 기타 연주
- Numpy
- C
- Selenium
- 프로그래머스
- YOLO
- mysql
- Linux
- pandas
- 핑거스타일
- Visual Studio
- pip
- C#
Archives
- Today
- Total
기계는 거짓말하지 않는다
C# Windows Forms 키 입력 필터 본문
숫자만 입력 또는 숫자와 소수점만 입력 (지우기는 가능함)
private void OnlyDigit_KeyPress(object sender, KeyPressEventArgs e) { if (!char.IsDigit(e.KeyChar)) // 숫자만 입력 { e.Handled = true; } } private void OnlyDigitAndDecimalPoint_KeyPress(object sender, KeyPressEventArgs e) // 숫자, 소수점만 입력 { if (!(char.IsDigit(e.KeyChar) || e.KeyChar == '.')) { e.Handled = true; } } private void OnlyChar_KeyPress(object sender, KeyPressEventArgs e) // 문자만 입력 { if (char.IsDigit(e.KeyChar)) { e.Handled = true; } }
Ctrl + V 를 이용하면 이벤트 적용이 되어 있더라도 복사가 되기 때문에 따로 처리를 하거나 예외 처리를 해주어야 한다.
'C#' 카테고리의 다른 글
C# 소수점 제한, 천 단위 콤마 출력 (0) | 2021.07.12 |
---|---|
C# Windows Forms MessageBox (0) | 2021.07.11 |
C# Windows Forms Clipboard 텍스트, 이미지 얻기 (0) | 2021.07.10 |
C# Windows Forms 키 입력 활성화, 동시 키 입력 (0) | 2021.07.07 |
C# using문, Dispose (0) | 2021.06.15 |