如何仅在控件上绘制选定的边框

 钟爱gyt_201 发布于 2023-01-07 13:37

我正在构建一个自定义控件,我需要它只绘制顶部边框.怎么做到呢?

编辑:目前我正在使用此代码:

protected override void OnPaint(PaintEventArgs e)
{
    if (!this.DesignMode)
    {
        Rectangle bounds = this.ClientRectangle;
        GraphicsPath topEdge = new GraphicsPath();
        topEdge.StartFigure();
        topEdge.AddLine(bounds.X, bounds.Y, bounds.X + bounds.Width, bounds.Y);
        topEdge.CloseFigure();
        e.Graphics.DrawPath(new Pen(SystemColors.ActiveBorder, 1), topEdge);
    }
    base.OnPaint(e);
}

当我的自定义控件中没有嵌套控件时,这很有效.一旦我开始添加控件,他们似乎过度绘制边框线.

1 个回答
  • 使用ControlPaint.DrawBorder方法.从本文中围绕任何C#Winform控件绘制边框:以下内容在控件周围添加边框:

    protected override void OnPaint(PaintEventArgs e)
    {
      base.OnPaint(e);
      ControlPaint.DrawBorder(e.Graphics, ClientRectangle,
                                Color.Black, BORDER_SIZE, ButtonBorderStyle.Inset,
                                Color.Black, BORDER_SIZE, ButtonBorderStyle.Inset,
                                Color.Black, BORDER_SIZE, ButtonBorderStyle.Inset,
                                Color.Black, BORDER_SIZE, ButtonBorderStyle.Inset);
    } 
    

    2023-01-07 13:39 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有