C# \charscalexN在RichTextBox上不工作

C# \charscalexN在RichTextBox上不工作,c#,winforms,rtf,C#,Winforms,Rtf,图像: 我的代码: private void BtnSetContent_Click(object sender, EventArgs e) { string fn = @"C:\Users\User\Documents\보통 글자.rtf"; string towrite = ""; StreamReader sr = new StreamReader(fn); while (sr.Peek() >= 0) { towr

图像:

我的代码:

private void BtnSetContent_Click(object sender, EventArgs e)
{
    string fn = @"C:\Users\User\Documents\보통 글자.rtf";
    string towrite = "";
    StreamReader sr = new StreamReader(fn);
    while (sr.Peek() >= 0)
    {
        towrite += sr.ReadLine() + " ";
    }
    sr.Close();
    MessageBox.Show(towrite);
    RTBMainText.Rtf = towrite;
}
我想在
RichTextBox
上显示200%拉伸的文本(例如
{\charscalex200拉伸}
),但该关键字似乎被忽略,因此
charscalex
显示的文本没有任何更改


是否有任何解决方案,普通的或带有一些额外的库来显示拉伸文本?

您需要使用最新版本的RichText库。创建自己的RichTextBox控件并重写CreateParams属性:

using System.Runtime.InteropServices;

public class RichBox : RichTextBox {

  [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
  private static extern IntPtr LoadLibrary(string lpFileName);

  protected override CreateParams CreateParams {
    get {
      var cp = base.CreateParams;
      if (LoadLibrary("msftedit.dll") != IntPtr.Zero) {
        cp.ClassName = "RICHEDIT50W";
      }
      return cp;
    }
  }
}
结果:

重新生成解决方案并使用此控件代替标准RichTextBox控件

此外,您还可以使用LoadFile方法:

richTextBox1.LoadFile(@"C:\Users\User\Documents\보통 글자.rtf");

你不需要这些代码。RichTextBox控件有一个LoadFile方法.Net
RichTextBox
类(可能)已经
RICHEDIT50W
。无论如何,不能保证它会处理该命令(我想说它不会)。但是它可以用
\fsN
来调整大小,其中N是字体高度(以像素为单位)。@Jimi可能不是。我测试了这个并复制了OP的问题,这为我解决了它。你是说,它可以缩放字体?正如我所说,在Windows7中,不能保证它不会(就像写字板一样)。但是.NET4.7中的类已经是
RICHEDIT50W
@Jimi Yes(我用一张图片更新了)。这是在.NET4.6.1上。我在Windows10上。我相信Windows7现在已经过时了。可能吧。只是一些OP可能感兴趣的信息。