首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

自定义panel控件解决方案

2013-10-23 
自定义panel控件VS2008 winform中panel控件不能更改边框线条颜色,想自己做一个可以定义边框线条颜色的,以

自定义panel控件
VS2008 winform中panel控件不能更改边框线条颜色,想自己做一个可以定义边框线条颜色的,以下是我代码,但报错,求指导.

public partial class TdPanel : UserControl
    {
        [DefaultValue(typeof(Color))]
        public Color LineColor
        {
            get { return LineColor; } 
            set { LineColor = value; }
        }

        public TdPanel()
        {
            InitializeComponent();
        }

        private void TdPanel_Resize(object sender, EventArgs e)
        {
            panel1.Size = this.Size;
        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {
            ControlPaint.DrawBorder(e.Graphics,
                                this.panel1.ClientRectangle,
                                this.LineColor,         //left
                                1,
                                ButtonBorderStyle.Solid,
                                this.LineColor,         //top
                                1,
                                ButtonBorderStyle.Solid,
                                this.LineColor,        //right
                                1,
                                ButtonBorderStyle.Solid,
                                this.LineColor,        //bottom
                                1,
                                ButtonBorderStyle.Solid);
        }
    }
  
[解决办法]

    public partial class TdPanel : UserControl
    {
        private Color lineColor = Color.Red;

        [DefaultValue(typeof(Color))]
        public Color LineColor
        {
            get { return lineColor; }
            set { lineColor = value; this.Invalidate(); }
        }



        public TdPanel()
        {
            InitializeComponent();
        }

        private void TdPanel_Paint(object sender, PaintEventArgs e)
        {
            ControlPaint.DrawBorder(e.Graphics,
                                ClientRectangle,
                                this.LineColor,         //left
                                1,
                                ButtonBorderStyle.Solid,
                                this.LineColor,         //top
                                1,
                                ButtonBorderStyle.Solid,
                                this.LineColor,        //right
                                1,
                                ButtonBorderStyle.Solid,
                                this.LineColor,        //bottom
                                1,
                                ButtonBorderStyle.Solid);
        }
    }

热点排行