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

效果:

相关推荐
m0_547486665 小时前
《JavaScript核心原理 》全套PPT课件2026
开发语言·javascript·ecmascript
MC皮蛋侠客5 小时前
Tauri 2.x 系列(五):调用系统 API——官方插件、Rust crate 与原生能力
开发语言·后端·rust
布莱克6056 小时前
软中断和硬中断的区别
开发语言·操作系统
whcyhhh6 小时前
头歌实践教学平台:数据科学与大数据技术导论(十二)
大数据·开发语言·python·数据清洗
lzhdim7 小时前
13、JavaScript事件循环机制 - JavaScript学习系列文章
开发语言·前端·javascript·学习·ecmascript
吴可可1237 小时前
多段线局部约束缩放实现
c#
zbyyd7 小时前
Linux 多线程:互斥锁 & 信号量
linux·c语言·开发语言·网络
wuyk5558 小时前
从零吃透Modbus通信|第3章:STM32 Modbus RTU主机
服务器·开发语言·网络·数据结构·stm32·单片机·嵌入式硬件
one3129 小时前
高精度MEMS电容式倾角传感器:原理、结构与Python三维可视化
开发语言·python
程序员小八7779 小时前
Go 语言特性
开发语言·后端·golang