how to disable copy, Paste and delete features on a textbox using C#

前端 未结 6 815
既然无缘
既然无缘 2020-11-27 04:57

Can anybody please suggest how to handle Cut,Copy and Paste events on a Text Box in WinForms using C#?

6条回答
  •  情话喂你
    2020-11-27 05:42

    To prevent users to copy/paste using the keyboard set ShortcutsEnabled property to false. To prevent users to copy/paste from the context menu set ContextMenu property to new ContextMenu().

    if (copyPasteEnabled) {
       textBox1.ShortcutsEnabled = true;
       textBox1.ContextMenu = null;
    } else {
       textBox1.ShortcutsEnabled = false;
       textBox1.ContextMenu = new ContextMenu();
    }
    

提交回复
热议问题