RichTextBox控件的用法举例
在C# winForm程序中。做一个日记本程序。想到需要图文混合排版。需要用RichTextBox这个控件。 private void button2_Click(object sender, System.EventArgs e) { Font oldFont = this.richTextBox1.SelectionFont; Font newFont;
if (oldFont.Bold) newFont = new Font(oldFont,oldFont.Style & ~FontStyle.Bold);
else newFont = new Font(oldFont,oldFont.Style | FontStyle.Bold);
this.richTextBox1.SelectionFont = newFont; this.richTextBox1.Focus(); } private void button7_Click(object sender, System.EventArgs e)
{ Font oldFont = this.richTextBox1.SelectionFont; Font newFont;
if (oldFont.Italic) newFont = new Font(oldFont,oldFont.Style & ~FontStyle.Italic);
else newFont = new Font(oldFont,oldFont.Style | FontStyle.Italic);
this.richTextBox1.SelectionFont = newFont; this.richTextBox1.Focus(); } private void button8_Click(object sender, System.EventArgs e)
{ Font oldFont = this.richTextBox1.SelectionFont; Font newFont;
if (oldFont.Underline) newFont = new Font(oldFont,oldFont.Style & ~FontStyle.Underline);
else newFont = new Font(oldFont,oldFont.Style | FontStyle.Underline);
this.richTextBox1.SelectionFont = newFont; this.richTextBox1 .Focus(); } richTextBox1.append(要添加的字符串);