(八十五)c#Winform自定义控件-引用区块-HZHControls

用处及效果

准备工作

没什么可准备的,直接往下看吧

开始

添加一个类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

原文出处:冰封一夏

原文链接:https://www.cnblogs.com/bfyx/p/11675488.html

本文观点不代表Dotnet9立场,转载请联系原作者。

发表评论

登录后才能评论