c# 绘制中间带文字的分割线

csharp 复制代码
public void DrawDeviceTitle(Graphics g, string title, int x, int y, int width)
{
    SizeF s = new SizeF();
    Font headerFont = new Font("MicrosoftYaHei", 10f, FontStyle.Regular);
    s = g.MeasureString(title, headerFont);
    SolidBrush br = new SolidBrush(Color.Black);
    StringFormat sf = new StringFormat();
    sf.Alignment = StringAlignment.Center;
    Pen p = new Pen(br);
    RectangleF rect = new RectangleF(x, y + 5, s.Width, s.Height);
    g.FillRectangle(Brushes.White, rect);
    g.DrawString(title, headerFont, br, rect, sf);
}

public void DrawSplitLine(Graphics g, string text, int x, int y, int width)
{
    x += 10;
    Pen p = new Pen(Color.Black, 1);
    Point p1 = new Point(x, y);
    Point p2 = new Point(x += width - 50, y);
    g.DrawLine(p, p1, p2);

    DrawDeviceTitle(g, text, x-(width - 50)+30, y - 10, text.Length);
}

效果:

相关推荐
Wang's Blog6 分钟前
Nodejs-HardCore: Buffer操作、Base64编码与zlib压缩实战
开发语言·nodejs
csbysj202014 分钟前
C# 集合(Collection)
开发语言
csbysj202027 分钟前
Lua 面向对象编程
开发语言
左直拳2 小时前
将c++程序部署到docker
开发语言·c++·docker
崇山峻岭之间2 小时前
Matlab学习记录31
开发语言·学习·matlab
bugcome_com2 小时前
C# 字符串拼接全面指南
c#·.net·wpf
你怎么知道我是队长3 小时前
C语言---输入和输出
c语言·开发语言
mmz12073 小时前
二分查找(c++)
开发语言·c++·算法
你怎么知道我是队长3 小时前
C语言---文件读写
java·c语言·开发语言