protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { Pen pen = new Pen(drawLineColor); pen.Width = 2; // 绘制一条水平分割线 e.Graphics.DrawLine(pen, new Point(5, 5), new Point(this.Width - 5, 5)); ////绘制panel的背景图像 //if (BackgroundImage != null) e.Graphics.DrawImage(this.BackgroundImage, new Point(0, 0)); } // 存储颜色值的内部变量 private Color drawLineColor = Color.Red; [Description("修改此值,可修改分割线的颜色"), Category("自定义属性")] // 控件的自定义属性值 public Color DrawLineColor { get { return drawLineColor; } set { drawLineColor = value; // 此处修改,为自定义属性变动时,执行的操作 // 此处当颜色值属性变动时,使用新的颜色,使自定义控件重绘 this.Invalidate(); } }