WinForm下禁止TextBox右键菜单

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/CLeopard/article/details/39319257

1 针对粘贴消息,但是会弹出菜单。

    public class MyTextBox : System.Windows.Forms.TextBox
    {
        public const int WM_PASTE = 0x0302;//粘貼消息 
        protected override void WndProc(ref Message m)
        {
            if (m.Msg != WM_PASTE) base.WndProc(ref m);
        }
    } 

2 替换右键菜单,变向禁止。

    public class MyTextBox : System.Windows.Forms.TextBox
    {
        public static MyTextBox t = new MyTextBox();
        public MyTextBox()
        {
            ContextMenuStrip contextMenuStrip = new System.Windows.Forms.ContextMenuStrip();
            t = this;
            t.ContextMenuStrip = contextMenuStrip;
        }
    } 


阅读更多

没有更多推荐了,返回首页