应该是写javascript得到的。具体的你就只有请教高人了!

解决方案 »

  1.   

    呵呵,我也正想找可是没找到,大概的意思就是在richtextbox的RTF属性里面写一些东西,但是怎么写我就不知道了,如果你找到答案记得告诉我,
      

  2.   

    http://www.codeproject.com/cs/miscctrl/csexrichtextbox.asp
      

  3.   

    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;namespace WinRichTextBox
    {
    /// <summary>
    /// Summary description for Form1.
    /// </summary>
    public class frmMain : System.Windows.Forms.Form
    {
    private System.Windows.Forms.Panel panel1;
    private System.Windows.Forms.Button btnUnload;
    private System.Windows.Forms.Button btnLoad;
    private System.Windows.Forms.RichTextBox rtb;
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.Container components = null; public frmMain()
    {
    //
    // Required for Windows Form Designer support
    //
    InitializeComponent(); //
    // TODO: Add any constructor code after InitializeComponent call
    //
    } /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if (components != null) 
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    } #region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
    this.panel1 = new System.Windows.Forms.Panel();
    this.btnUnload = new System.Windows.Forms.Button();
    this.btnLoad = new System.Windows.Forms.Button();
    this.rtb = new System.Windows.Forms.RichTextBox();
    this.panel1.SuspendLayout();
    this.SuspendLayout();
    // 
    // panel1
    // 
    this.panel1.Controls.Add(this.btnUnload);
    this.panel1.Controls.Add(this.btnLoad);
    this.panel1.Dock = System.Windows.Forms.DockStyle.Top;
    this.panel1.Location = new System.Drawing.Point(0, 0);
    this.panel1.Name = "panel1";
    this.panel1.Size = new System.Drawing.Size(544, 40);
    this.panel1.TabIndex = 1;
    // 
    // btnUnload
    // 
    this.btnUnload.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
    this.btnUnload.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
    this.btnUnload.ForeColor = System.Drawing.SystemColors.ControlText;
    this.btnUnload.Location = new System.Drawing.Point(88, 8);
    this.btnUnload.Name = "btnUnload";
    this.btnUnload.Size = new System.Drawing.Size(64, 23);
    this.btnUnload.TabIndex = 4;
    this.btnUnload.Text = "清 除";
    this.btnUnload.Click += new System.EventHandler(this.btnUnload_Click);
    // 
    // btnLoad
    // 
    this.btnLoad.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
    this.btnLoad.Location = new System.Drawing.Point(16, 8);
    this.btnLoad.Name = "btnLoad";
    this.btnLoad.Size = new System.Drawing.Size(64, 23);
    this.btnLoad.TabIndex = 3;
    this.btnLoad.Text = "加 载";
    this.btnLoad.Click += new System.EventHandler(this.btnLoad_Click);
    // 
    // rtb
    // 
    this.rtb.BackColor = System.Drawing.SystemColors.GrayText;
    this.rtb.BorderStyle = System.Windows.Forms.BorderStyle.None;
    this.rtb.Dock = System.Windows.Forms.DockStyle.Fill;
    this.rtb.Location = new System.Drawing.Point(0, 40);
    this.rtb.Name = "rtb";
    this.rtb.Size = new System.Drawing.Size(544, 389);
    this.rtb.TabIndex = 2;
    this.rtb.Text = "";
    // 
    // frmMain
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
    this.ClientSize = new System.Drawing.Size(544, 429);
    this.Controls.Add(this.rtb);
    this.Controls.Add(this.panel1);
    this.Name = "frmMain";
    this.Text = "WinRichTextBoxFormatTest";
    this.panel1.ResumeLayout(false);
    this.ResumeLayout(false); }
    #endregion /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main() 
    {
    Application.Run(new frmMain());
    } private void btnLoad_Click(object sender, System.EventArgs e)
    {
    rtb.Clear(); //定义四个文本部分,便于分别应用不同的文本格式
    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;

    } private void btnUnload_Click(object sender, System.EventArgs e)
    {
    rtb.Clear();
    }
    }
    }
      

  4.   

    参照RTF格式
    用词法分析,然后加上RTF的TAG
      

  5.   

    this.richTextBox1.SaveFile(save.FileName,RichTextBoxStreamType.RichText);
    可以进行保存颜色与字体。
      

  6.   

    提供一个笨办法,但是很奏效。比如说关键字有“int”“float”,在你将文件Load到RichTextBox中时,先设置选中文本的颜色,比如红色,再进行扫描字符串,每次“int”“float”出现时,将其置为选中状态,则该词就可以变成红色了。