1 public partial class Form1 : Form
  2     {
  3         public Form1()
  4         {
  5             InitializeComponent();
  6             
  7         }
  8 //创建font对象
  9 
 10         Font font;
 11 //对richtextbox加粗
 12         private void checkBox1_CheckedChanged(object sender, EventArgs e)
 13         {
 14             FontStyle FontStyle1;
 15             FontStyle1 = FontStyle.Regular;         
 16             if (checkBox1.Checked)
 17             {
 18                 FontStyle1 = FontStyle.Bold;
 19             }          
 20 
 21             font = new Font(richTextBox1.Font, FontStyle1 );
 22             richTextBox1.Font = font;
 23         }
 24         private void Form1_Load(object sender, EventArgs e)
 25         {
 26 //3个combox默认显示内容
 27             comboBox1.SelectedIndex = 1;
 28             comboBox2.SelectedIndex = 0;
 29             comboBox3.SelectedIndex = 3;
 30             richTextBox1.AppendText("fsdfsj");
 31         }
 32 //改变字体号数
 33         private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
 34         {
 35             float sizecb1 = Convert.ToSingle(comboBox1.SelectedItem);
 36             font = new Font(richTextBox1.Font.FontFamily, sizecb1);
 37             richTextBox1.Font = font;
 38         }
 39 //改变字体名称
 40         private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
 41         {
 42             string name = font.FontFamily.Name;
 43             name = comboBox2.SelectedItem.ToString();
 44             font = new Font(name, richTextBox1.Font.Size, richTextBox1.Font.Style);
 45             richTextBox1.Font = font;
 46 
 47         }
 48 //改变字体颜色
 49         private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
 50         {
 51             Color color = richTextBox1.ForeColor;
 52            
 53             //richTextBox1.ForeColor = color;
 54             switch (comboBox3.SelectedItem.ToString())
 55             {
 56                 case "蓝色":
 57                  color = Color.Blue;
 58                     break;
 59                 case "黄色":
 60                     color = Color.Yellow;
 61                     break;
 62                 case "白色":
 63                     color = Color.White;
 64                     break;
 65                 case "红色":
 66                     color = Color.Red;
 67                     break;
 68                 case "绿色":
 69                     color = Color.Green;
 70                     break;
 71                 case "黑色":
 72                     color = Color.Black;
 73                     break;              
 74                 default:
 75                     break;
 76             }
 77             richTextBox1.ForeColor = color;
 78         }
 79 
 80 //字体变斜体
 81         private void checkBox2_CheckedChanged(object sender, EventArgs e)
 82         {
 83             FontStyle FontStyle2;
 84             FontStyle2 = FontStyle.Regular;
 85             if (checkBox2.Checked)
 86             {
 87                 FontStyle2 = FontStyle.Italic;
 88             }
 89             font = new Font(richTextBox1.Font, FontStyle2);
 90             richTextBox1.Font = font;
 91         }
 92 //字体加下滑线
 93         private void checkBox3_CheckedChanged(object sender, EventArgs e)
 94         {
 95             FontStyle FontStyle3;
 96             FontStyle3 = FontStyle.Regular;
 97             if (checkBox3.Checked)
 98             {
 99                 FontStyle3 = FontStyle.Underline;
100             }
101             font = new Font(richTextBox1.Font, FontStyle3);
102             richTextBox1.Font = font;
103         }
104 //字体加删除线
105         private void checkBox4_CheckedChanged(object sender, EventArgs e)
106         {
107             FontStyle FontStyle4;
108             FontStyle4 = FontStyle.Regular;
109             if (checkBox4.Checked)
110             {
111                 FontStyle4 = FontStyle.Strikeout;
112             }
113             font = new Font(richTextBox1.Font, FontStyle4);
114             richTextBox1.Font = font;
115         }
116     }

 

Posted on 2023-03-04 23:36  lt柱  阅读(46)  评论(0编辑  收藏  举报