如何设置字体大小 [英] How to set font size

查看:100
本文介绍了如何设置字体大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码



我正在生成docx我无法设置字体大小8



 受保护  void  Page_Load( object  sender,EventArgs e)
{
string path = @ C:\ Users \ amalraj.a\Desktop\032114 \ RTF\J50 OHIO 999.64.RTF;

System.Windows.Forms.RichTextBox rtBox = new System.Windows.Forms.RichTextBox();
rtBox.Rtf = System.IO.File.ReadAllText(path); ;
// rtBox.SelectionFont = new Font(Courier New,8,FontStyle.Regular);
// rtBox.SelectionFont = new Font(Courier New,8);
rtBox.Font = new System.Drawing.Font( new System.Drawing。 FontFamily( Courier New), 8 .00F,System.Drawing.FontStyle.Regular); // 此处设置的字体无效
rtBox.SaveFile( @ C:\ Users \ amalraj.a\Desktop\032114 \\ \\ output.\\TestDocument.docx,RichTextBoxStreamType.PlainText);
}

解决方案

尝试选择文字:

 rtBox.Rtf = System.IO.File.ReadAllText(path); ; 
rtBox.SelectAll();
rtBox.SelectionFont = new 字体( new System.Drawing.FontFamily( Courier New), 8 .00F,System。 Drawing.FontStyle.Regular);



但是......因为你将它保存为纯文本,所以你扔掉了所有的格式 - 包括字体样式 - 无论如何! br />
这可能有效:

 System.Windows.Forms.RichTextBox rtBox =  new  System.Windows.Forms.RichTextBox(); 
rtBox.Rtf = System.IO.File.ReadAllText( @ D:\Temp \ MyRTF .RTF);
rtBox.SelectAll();
rtBox.SelectionFont = new 字体( new System.Drawing.FontFamily( Courier New), 8 .00F,System。 Drawing.FontStyle.Regular);
rtBox.SaveFile( @ D:\Temp \ MyYTFOut.rtf) ;


This my code

i'm generating docx i can't set set font size 8

protected void Page_Load(object sender, EventArgs e)
        {
            string path = @"C:\Users\amalraj.a\Desktop\032114\RTF\J50 OHIO 999.64.RTF";

            System.Windows.Forms.RichTextBox rtBox = new System.Windows.Forms.RichTextBox();
            rtBox.Rtf = System.IO.File.ReadAllText(path); ;
            // rtBox.SelectionFont = new Font("Courier New", 8, FontStyle.Regular);
            //rtBox.SelectionFont = new Font("Courier New", 8);
            rtBox.Font = new System.Drawing.Font(new System.Drawing.FontFamily("Courier New"), 8.00F, System.Drawing.FontStyle.Regular);//font set here has no effect
            rtBox.SaveFile(@"C:\Users\amalraj.a\Desktop\032114\output\TestDocument.docx", RichTextBoxStreamType.PlainText);
        }

解决方案

Try selecting the text:

rtBox.Rtf = System.IO.File.ReadAllText(path); ;
rtBox.SelectAll();
rtBox.SelectionFont = new Font(new System.Drawing.FontFamily("Courier New"), 8.00F, System.Drawing.FontStyle.Regular);


But...since you are saving it as plaintext, you are throwing away all of the formatting - including font style - anyway!
This might work:

System.Windows.Forms.RichTextBox rtBox = new System.Windows.Forms.RichTextBox();
rtBox.Rtf = System.IO.File.ReadAllText(@"D:\Temp\MyRTF.RTF");
rtBox.SelectAll();
rtBox.SelectionFont = new Font(new System.Drawing.FontFamily("Courier New"), 8.00F, System.Drawing.FontStyle.Regular);
rtBox.SaveFile(@"D:\Temp\MyRTFOut.rtf");


这篇关于如何设置字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆