文章目录
用处及效果

准备工作
没什么可准备的,直接往下看吧
开始
添加一个类UCPanelQuote继承 Panel
添加2个属性
/// <summary>
/// The border color
/// </summary>
private Color borderColor = LineColors.Light;
/// <summary>
/// Gets or sets the color of the border.
/// </summary>
/// <value>The color of the border.</value>
[Description("边框颜色"), Category("自定义")]
public Color BorderColor
{
get { return borderColor; }
set
{
borderColor = value;
this.Invalidate();
}
}
/// <summary>
/// The left color
/// </summary>
private Color leftColor = StatusColors.Danger;
/// <summary>
/// Gets or sets the color of the left.
/// </summary>
/// <value>The color of the left.</value>
[Description("左侧颜色"), Category("自定义")]
public Color LeftColor
{
get { return leftColor; }
set
{
leftColor = value;
this.Invalidate();
}
}
为了画边框和左边的颜色,设置一下Padding
public UCPanelQuote() : base()
{
Padding = new Padding(5, 1, 1, 1);
}
重绘
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
e.Graphics.SetGDIHigh();
e.Graphics.DrawLines(new Pen(borderColor), new Point[]
{
new Point(e.ClipRectangle.Left,e.ClipRectangle.Top),
new Point(e.ClipRectangle.Right-1,e.ClipRectangle.Top),
new Point(e.ClipRectangle.Right-1,e.ClipRectangle.Bottom-1),
new Point(e.ClipRectangle.Left,e.ClipRectangle.Bottom-1),
new Point(e.ClipRectangle.Left,e.ClipRectangle.Top)
});
e.Graphics.FillRectangle(new SolidBrush(leftColor), new Rectangle(0, 0, 5, this.Height));
}
最后的话
如果你喜欢的话,请到 https://gitee.com/kwwwvagaa/net_winform_custom_control 点个星星吧
作者:冰封一夏
出处: http://www.hzhcontrols.com/doc.html
HZHControls官网:http://www.hzhcontrols.com
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,
且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
GitHub:https://github.com/kwwwvagaa/NetWinformControl
码云:https://gitee.com/kwwwvagaa/net_winform_custom_control.git