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

效果:

相关推荐
aaaameliaaa30 分钟前
计算斐波那契数(递归、迭代)(1,1,2,3,5.....)
c语言·开发语言·笔记·算法·排序算法
m0_5474866636 分钟前
《模式识别:使用MATLAB分析与实现》全套PPT课件
开发语言·matlab·模式识别
Tim_1036 分钟前
【C++】009、extern关键字
java·开发语言
夜雪一千1 小时前
Python 使用OpenAI调用Qwen3.6-27B-ms模型|完整参数详解
开发语言·python
zhiSiBuYu05172 小时前
重排序(Rerank)提升检索准确率实战指南
开发语言·python·算法
c++之路2 小时前
C++跨平台(九):跨平台字节序统一处理
开发语言·arm开发·c++
Evand J3 小时前
【MATLAB例程|车联网6】考虑调头车流扰动与网联车辆实时感知信息的干线多交叉口 FAC-CV 全感应协调控制仿真与性能对比分析
开发语言·matlab·仿真·代码·车联网·智慧交通·车辆
云絮.3 小时前
数据库事务
java·开发语言·数据库
派葛穆3 小时前
Python-pip切换镜像源
开发语言·python·pip