C#学习笔记-自定义控件边框颜色

label边框

        /// 
        /// 自定义边框颜色
        /// 
        public Color BorderColor { get; set; }

        protected override void WndProc(ref Message m)
        {
            base.WndProc(ref m);
            if (m.Msg == 0xf || m.Msg == 0x133)
            {
                if (this.BorderStyle == BorderStyle.None)
                {
                    System.Drawing.Pen pen = new Pen(this.BorderColor, 1);
                    Graphics g = Graphics.FromHwnd(m.HWnd);
                    g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                    g.DrawRectangle(pen, 0, 0, this.Width -1, this.Height-1);
                    pen.Dispose();
                }
                //返回结果
                m.Result = IntPtr.Zero;
            }
        }

richtextbox

        /// 
        /// 自定义边框颜色
        /// 
        public Color BorderColor { get; set; }

        protected override void WndProc(ref Message m)
        {
            base.WndProc(ref m);
            if (m.Msg == 0xf || m.Msg == 0x133)
            {
                if (this.BorderStyle == BorderStyle.None)
                {
                    System.Drawing.Pen pen = new Pen(this.BorderColor, 1);
                    Graphics g = Graphics.FromHwnd(m.HWnd);
                    g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                    g.DrawRectangle(pen, 0, 0, this.Width - 1, this.Height - 1);
                    pen.Dispose();
                }
                //返回结果
                m.Result = IntPtr.Zero;
            }
        }

textbox

        /// 
        /// 自定义边框颜色
        /// 
        public Color BorderColor { get; set; }

        protected override void WndProc(ref Message m)
        {
            base.WndProc(ref m);
            if (m.Msg == 0xf || m.Msg == 0x133)
            {
                if (this.BorderStyle == BorderStyle.FixedSingle)
                {
                    System.Drawing.Pen pen = new Pen(this.BorderColor, 1);
                    Graphics g = Graphics.FromHwnd( m.HWnd);
                    g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                    g.DrawRectangle(pen, 0, 0, this.Width - 1, this.Height - 1);
                    pen.Dispose();
                }
                //返回结果
                m.Result = IntPtr.Zero;
            }
        }

comboBox

        /// 
        /// 自定义边框颜色
        /// 
        public Color BorderColor { get; set; }

        protected override void WndProc(ref Message m)
        {
            base.WndProc(ref m);
            if (m.Msg == 0xf || m.Msg == 0x133)
            {
                if (this.FlatStyle == FlatStyle.Flat)
                {
                    System.Drawing.Pen pen = new Pen(this.BorderColor, 1);
                    Graphics g = Graphics.FromHwnd(m.HWnd);
                    g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                    g.DrawRectangle(pen, 0, 0, this.Width - 1, this.Height - 1);
                    pen.Dispose();
                }
                //返回结果
                m.Result = IntPtr.Zero;
            }
        }

你可能感兴趣的:(自定义,控件操作,C#,自定义,控件边框颜色)