具有只读属性的ComboBox

效果同TextBox的ReadOnly

    public class ComboBoxTest : ComboBox     {         private bool _ReadOnly;

        public ComboBoxTest()             : base()         {         }

        public bool ReadOnly         {             get             {                 return this._ReadOnly;             }             set             {                 this._ReadOnly = value;                 this.TabStop = !value;                 if (value)                     this.BackColor = System.Drawing.SystemColors.Control;                 else                     this.BackColor = System.Drawing.SystemColors.Window;             }         }

        protected override void WndProc(ref Message m)         {             if (this._ReadOnly && (m.Msg == 0xa1 || m.Msg == 0x200 || m.Msg == 0x201 ||                 m.Msg == 0x202 || m.Msg == 0x203 || m.Msg == 0x204 || m.Msg == 0x205 ||                 m.Msg == 0x206 || m.Msg == 0x207 || m.Msg == 0x208 || m.Msg == 0x209))             {                 return;             }             base.WndProc(ref m);         }            }

另外

WM_MOUSEMOVE = 0x200 WM_LBUTTONDOWN = 0x201 WM_RBUTTONDOWN = 0x204 WM_MBUTTONDOWN = 0x207 WM_LBUTTONUP = 0x202 WM_RBUTTONUP = 0x205 WM_MBUTTONUP = 0x208 WM_LBUTTONDBLCLK = 0x203 WM_RBUTTONDBLCLK = 0x206 WM_MBUTTONDBLCLK = 0x209

转载于:https://my.oschina.net/cjkall/blog/195879

猜你喜欢

转载自blog.csdn.net/weixin_34244102/article/details/91756086