111,126
社区成员
发帖
与我相关
我的任务
分享
public class RichText
{
public RichText(string Text)
:this(Text,12f,Color.Black)
{
}
public RichText(string Text, float Size, Color Color)
:this(Text,"宋体",Size,false,false,false,Color)
{
}
public RichText(string Text, string FontName, float Size, bool Bold, bool Italic, bool Underline, Color Color)
{
this.Text = Text;
this.Color = Color;
FontStyle style = FontStyle.Regular;
if (Bold)
style |= FontStyle.Bold;
if (Italic)
style |= FontStyle.Italic;
if (Underline)
style |= FontStyle.Underline;
this.Font = new Font(FontName, Size, style);
}
public string Text { get; set; }
public Font Font { get; set; }
public Color Color { get; set; }
}
public void AppentRichText(RichText RichText)
{
int start = this.richTextBox1.TextLength;
this.richTextBox1.AppendText(RichText.Text);
this.richTextBox1.SelectionStart = start;
this.richTextBox1.SelectionLength = RichText.Text.Length;
this.richTextBox1.SelectionFont = RichText.Font;
this.richTextBox1.SelectionColor = RichText.Color;
this.richTextBox1.SelectionStart = this.richTextBox1.TextLength;
}
private void Form1_Load(object sender, EventArgs e)
{
RichText mytext = new RichText("这是一个测试", 12f, Color.Red);
RichText mytext2 = new RichText("这是第二个测试", "楷体", 16f, false, true, false, Color.SteelBlue);
AppentRichText(mytext);
AppentRichText(mytext2);
}