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

效果:

相关推荐
mudtools1 小时前
.NET驾驭Word之力:玩转文本与格式
c#·.net
唐青枫4 小时前
C#.NET 数据库开发提速秘籍:SqlSugar 实战详解
c#·.net
mudtools21 小时前
.NET驾驭Word之力:理解Word对象模型核心 (Application, Document, Range)
c#·.net
侃侃_天下1 天前
最终的信号类
开发语言·c++·算法
echoarts1 天前
Rayon Rust中的数据并行库入门教程
开发语言·其他·算法·rust
Aomnitrix1 天前
知识管理新范式——cpolar+Wiki.js打造企业级分布式知识库
开发语言·javascript·分布式
大飞pkz1 天前
【设计模式】C#反射实现抽象工厂模式
设计模式·c#·抽象工厂模式·c#反射·c#反射实现抽象工厂模式
每天回答3个问题1 天前
UE5C++编译遇到MSB3073
开发语言·c++·ue5
伍哥的传说1 天前
Vite Plugin PWA – 零配置构建现代渐进式Web应用
开发语言·前端·javascript·web app·pwa·service worker·workbox
小莞尔1 天前
【51单片机】【protues仿真】 基于51单片机八路抢答器系统
c语言·开发语言·单片机·嵌入式硬件·51单片机