C# RichTextBox显示不同格式的字体

C# RichTextBox显示不同格式的字体

            txtBox.AppendText(titile);
            txtBox.Select(0, titile.Length);
            txtBox.SelectionColor = System.Drawing.Color.Blue;

或者:

       txtBox.SelectionStart = 0;

      txtBox.SelectionLength = 5;

txtBox.SelectionColor = System.Drawing.Color.Blue;

转自:http://blog.sina.com.cn/s/blog_4b3485000100slj9.html

 
                    //定义四个文本部分,便于分别应用不同的文本格式
                      string firstString = "大山的骄傲\r\n ";
                      string secondString = "——eheartcool其人\r\n\r ";
                      string thirdString = "\t七十年代末的一个夜晚,没有星星,也没有月亮," +"中国湖北恩施的小山村正沉浸在睡梦中,几声婴儿的哭嘀和紧接的爆竹声" + "冲破了夜的沉默,一个新的生命诞生了!\r\n";
                      string fourthString = "未完待续…… ";
                      rtb.Text = firstString;
                      rtb.Text += secondString;
                      rtb.Text += thirdString;
                      rtb.Text += fourthString;

                      //对标题应用格式
                      rtb.SelectionStart = 0;
                      rtb.SelectionLength = firstString.Length - 1;
                      rtb.SelectionFont = new System.Drawing.Font("黑体 ", 18F,
                              System.Drawing.FontStyle.Bold,System.Drawing.GraphicsUnit.Point,
                              ((System.Byte)(0)));
                      rtb.SelectionColor = System.Drawing.Color.Blue;
                      rtb.SelectionAlignment = HorizontalAlignment.Center;

                      //对副标题应用格式
                      rtb.SelectionStart = firstString.Length - 1;
                      rtb.SelectionLength = secondString.Length;
                      rtb.SelectionFont = new System.Drawing.Font("黑体 ", 12F,
                              System.Drawing.FontStyle.Regular,System.Drawing.GraphicsUnit.Point,
                              ((System.Byte)(0)));
                      rtb.SelectionAlignment = HorizontalAlignment.Center;
                      rtb.SelectionColor = System.Drawing.Color.Black;

                      //对正文应用格式
                      rtb.SelectionStart = firstString.Length + secondString.Length -1;
                      rtb.SelectionLength = thirdString.Length;
                      rtb.SelectionFont = new System.Drawing.Font("宋体 ", 10F,
                              System.Drawing.FontStyle.Regular,System.Drawing.GraphicsUnit.Point,
                              ((System.Byte)(0)));
                      rtb.SelectionColor = System.Drawing.Color.Black;
                      rtb.SelectionAlignment = HorizontalAlignment.Left;

                      //对结尾应用格式
                      rtb.SelectionStart = firstString.Length +
                              secondString.Length + thirdString.Length - 1;
                      rtb.SelectionLength = fourthString.Length;
                      rtb.SelectionFont = new System.Drawing.Font("宋体 ", 10F,
                              System.Drawing.FontStyle.Regular,System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
                      rtb.SelectionColor = System.Drawing.Color.Black;
                      rtb.SelectionAlignment = HorizontalAlignment.Right;

C# <wbr>RichTextBox显示不同格式的字体
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值