【求助】屏蔽TextBox默认右键菜单
各位大侠:
如果要屏蔽TextBox的默认右键菜单部分菜单项,同时保留部分菜单项(如:复制,粘贴,删除),是要继承该控件进行重写还是可以直接设定呢? 有没相关的实例,谢谢!
public partial class NoPraseTextBox : System.Windows.Forms.TextBox { private const int WM_GETTEXT = 0x000d; private const int WM_COPY = 0x0301; private const int WM_PASTE = 0x0302; private const int WM_CONTEXTMENU = 0x007B; private const int WM_RBUTTONDOWN = 0x0204; public NoPraseTextBox() { InitializeComponent(); // // TODO: 在此处添加构造函数逻辑 // } protected override void WndProc(ref Message m) { if (m.Msg == WM_RBUTTONDOWN) return;//WM_RBUTTONDOWN是为了不让出现鼠标菜单 base.WndProc(ref m); } protected override void OnPaint(PaintEventArgs pe) { base.OnPaint(pe); } }