图片:
我的代码:
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% 拉伸(stretch)的文本(例如 {\charscalex200 Stretched}
),但是这个关键字似乎被忽略了,所以 charscalex
显示的文本没有变化。
是否有任何解决方案(普通的或一些额外的库)来显示拉伸(stretch)的文本?
您需要使用最新版本的 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");
我是一名优秀的程序员,十分优秀!