【问题标题】:Is it possible to stretch font in WinForms是否可以在 WinForms 中拉伸字体
【发布时间】:2013-12-14 09:45:47
【问题描述】:

是否可以在 WinForms 中拉伸字体?我想要完成的是将字体拉伸到最大可用 RichTextBox 宽度。它应该类似于 WPF 中的视图框。 我的目标是拉伸字体而不是调整它的大小。我使用的所有字体都是等距字体。

【问题讨论】:

  • AFAIK 这不可能。您可以做的是模仿(或多或少)WPF 所做的事情:将您的 rtb 绘制成位图,然后拉伸该位图。
  • Graphics.ScaleTransform + Graphics.DrawString。但这对 RichTextBox 来说是一个很大的问题,就像其他由 Windows 实际实现的控件一样,它们会进行自己的文本渲染。

标签: c# winforms fonts richtextbox


【解决方案1】:

是的,可以这样做

 private void button1_Click(object sender, EventArgs e)
    {
        Graphics gr = richTextBox1.CreateGraphics();
        Brush brush = new SolidBrush(Color.Red);
        float x = 0.0F;
        float y = 0.0F;
        float width = 200.0F;
        float height = 50.0F;
        Font drawFont = new Font("Arial", 18);

        RectangleF drawRect = new RectangleF(x, y, width, height);
         //here you  can shrink  as you want 
        gr.ScaleTransform(3, 1);
        gr.DrawString("your text", drawFont, brush, drawRect);

    }

希望对你有所帮助

【讨论】:

  • 抱歉,它只创建了 RichTextBox 内容的位图。我知道这个解决方案,但是使用它你失去了使用文本的可能性。选择它或搜索。我正在 WPF 中寻找类似 viewbox 的东西。可能是 WinForms 的第三方组件。
猜你喜欢
  • 2012-04-11
  • 2011-08-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多