c# - 在 WinForms 中绘制垂直堆叠的文本

标签 c# .net winforms text system.drawing

最好使用 Graphics 对象,如何绘制字符串以使字符仍然正常定向,但垂直堆叠?

最佳答案

只需将字符串拆分为字符并绘制每个字符,将字体的行高添加到 Y 轴变量:

    protected override void OnPaint(PaintEventArgs e)
    {
        float x = 10.0F;
        float y = 10.0F;

        string drawString = "123";

        using(SolidBrush brush = new SolidBrush(Color.Black))
        using (Font drawFont = new Font("Arial", 16))
        {
            foreach (char c in drawString.ToCharArray())
            {
                PointF p = new PointF(x, y);
                e.Graphics.DrawString(c.ToString(), drawFont, brush, p);

                y += drawFont.Height;
            }
        }
        base.OnPaint(e);
    }

关于c# - 在 WinForms 中绘制垂直堆叠的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1521157/

相关文章:

.net - 正在寻找使用 .NET 和 Mono 开发 iPhone 应用程序的好教程

c# - 如何更改 winform DataGridview 标题的颜色?

c# - 使用 C# 在 Windows 窗体应用程序上读取和显示 CSV 文件中的数据

c# - 如果 DataRowCollection 的基类派生自 IEnumerable<T>,为什么不能在 DataRowCollection 上使用 LINQ

C# 正则表达式匹配

c# - DataGridView 中显示的来自 XML 的数据集

c# - 处理 Quartz.NET 的正确方法?

c# - 如何动态或在运行时设置 PropertyGrid 的 DefaultValueAttribute?

c# - float 变量格式

c# - 交换约会中的换行符