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

效果:

相关推荐
西北大程序猿19 分钟前
单例模式与锁(死锁)
linux·开发语言·c++·单例模式
你不是我我30 分钟前
【Java开发日记】说一说 SpringBoot 中 CommandLineRunner
java·开发语言·spring boot
心扬41 分钟前
python网络编程
开发语言·网络·python·tcp/ip
qq_454175791 小时前
c++学习-this指针
开发语言·c++·学习
Rose 使者1 小时前
全球IP归属地查询接口如何用C#进行调用?
c#·api·ip地址
尘浮7281 小时前
60天python训练计划----day45
开发语言·python
sss191s1 小时前
校招 java 面试基础题目及解析
java·开发语言·面试
sduwcgg2 小时前
python的numpy的MKL加速
开发语言·python·numpy
钢铁男儿2 小时前
Python 接口:从协议到抽象基 类(定义并使用一个抽象基类)
开发语言·python
暴力求解2 小时前
C++类和对象(上)
开发语言·c++·算法