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);
}

效果:

相关推荐
这是程序猿12 分钟前
基于java的ssm框架旅游在线平台
java·开发语言·spring boot·spring·旅游·旅游在线平台
芳草萋萋鹦鹉洲哦16 分钟前
【elemen/js】阻塞UI线程导致的开关卡顿如何优化
开发语言·javascript·ui
爱学习的小邓同学20 分钟前
C++ --- 多态
开发语言·c++
颜*鸣&空28 分钟前
QT实现串口通信+VSPD+串口调试工具
开发语言·qt
槁***耿1 小时前
JavaScript在Node.js中的事件发射器
开发语言·javascript·node.js
U***49831 小时前
JavaScript在Node.js中的Strapi
开发语言·javascript·node.js
@大迁世界1 小时前
相信我兄弟:Cloudflare Rust 的 .unwrap() 方法在 330 多个数据中心引发了恐慌
开发语言·后端·rust
大侠课堂1 小时前
C#经典面试题100道
开发语言·c#
X***E4631 小时前
PHP在电商中的订单处理
开发语言·php
Old_Driver_Lee1 小时前
C语言常用语句
c语言·开发语言