自定义panel控件

流星落2013 2013-10-22 03:48:27
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);
}
}
...全文
90 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
流星落2013 2013-10-22
  • 打赏
  • 举报
回复
太感谢你了,真的好了,就是你这个方法
智商余额不足 2013-10-22
  • 打赏
  • 举报
回复

    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);
        }
    }
流星落2013 2013-10-22
  • 打赏
  • 举报
回复
一放就VS崩溃了
智商余额不足 2013-10-22
  • 打赏
  • 举报
回复
引用 2 楼 omidy 的回复:
[quote=引用 1 楼 hwenycocodq520 的回复:]

[DefaultValue(typeof(Color),"Gray")]
public Color LineColor
{
     get { return LineColor; } 
     set { LineColor = value; }
}
哥,不行啊,一放就崩溃了[/quote] 说什么错?
tcmakebest 2013-10-22
  • 打赏
  • 举报
回复
楼主为何不直接从 Panel 继承?
流星落2013 2013-10-22
  • 打赏
  • 举报
回复
引用 1 楼 hwenycocodq520 的回复:

[DefaultValue(typeof(Color),"Gray")]
public Color LineColor
{
     get { return LineColor; } 
     set { LineColor = value; }
}
哥,不行啊,一放就崩溃了
智商余额不足 2013-10-22
  • 打赏
  • 举报
回复

[DefaultValue(typeof(Color),"Gray")]
public Color LineColor
{
     get { return LineColor; } 
     set { LineColor = value; }
}

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧