■ Control 클래스의 ProcessCmdKey 메소드를 사용해 COPY/PASTE/CUT을 방지하는 방법을 보여준다.
▶ CustomTextBox.cs
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
using System.Windows.Forms; namespace TestProject { /// <summary> /// 커스텀 텍스트 박스 /// </summary> public class CustomTextBox : TextBox { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// COPY 키 /// </summary> private const Keys CopyKeys = Keys.Control | Keys.C; /// <summary> /// PASTE 키 /// </summary> private const Keys PasteKeys = Keys.Control | Keys.V; /// <summary> /// CUT 키 /// </summary> private const Keys CutKeys = Keys.Control | Keys.X; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Static #region 명령 키 처리하기 - ProcessCmdKey(message, keyData) /// <summary> /// 명령 키 처리하기 /// </summary> /// <param name="message">메시지</param> /// <param name="keyData">키 데이터</param> /// <returns>처리 결과</returns> protected override bool ProcessCmdKey(ref Message message, Keys keyData) { if(keyData == CopyKeys || keyData == PasteKeys || keyData == CutKeys) { return true; } else { return base.ProcessCmdKey(ref message, keyData); } } #endregion } } |