(1)



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 单选按钮和复选框的使用
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            textBox1.Font = new Font("宋体", textBox1.Font.Size, textBox1.Font.Style);
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            textBox1.Font = new Font("隶书", textBox1.Font.Size, textBox1.Font.Style);
        }

        private void radioButton3_CheckedChanged(object sender, EventArgs e)
        {
            textBox1.Font = new Font("楷体", textBox1.Font.Size, textBox1.Font.Style);
        }

        private void radioButton4_CheckedChanged(object sender, EventArgs e)
        {
            textBox1.Font = new Font(textBox1.Font.FontFamily,9,textBox1.Font.Style);
        }

        private void radioButton5_CheckedChanged(object sender, EventArgs e)
        {
            textBox1.Font = new Font(textBox1.Font.FontFamily, 15.75f, textBox1.Font.Style);
        }

        private void radioButton6_CheckedChanged(object sender, EventArgs e)
        {
            textBox1.Font = new Font(textBox1.Font.FontFamily, 26.25f, textBox1.Font.Style);
        }
        private void changeTextStyle() {

            FontStyle fStyle = textBox1.Font.Style;
            if (checkBox1.Checked == true && checkBox3.Checked == true && checkBox2.Checked == true)
            {
                fStyle = (FontStyle)(FontStyle.Bold | FontStyle.Italic | FontStyle.Underline);

            }
            else if (checkBox1.Checked == true && checkBox2.Checked == true)
            {
                fStyle = (FontStyle)(FontStyle.Bold | FontStyle.Italic);

            }
            else if (checkBox1.Checked == true && checkBox3.Checked == true)
            {
                fStyle = (FontStyle)(FontStyle.Bold | FontStyle.Underline);

            }
            else if (checkBox2.Checked == true && checkBox3.Checked == true)
            {
                fStyle = (FontStyle)(FontStyle.Italic | FontStyle.Underline);

            }
            else if (checkBox1.Checked == true)
            {
                fStyle = (FontStyle)(FontStyle.Bold);

            }
            else if (checkBox2.Checked == true)
            {
                fStyle = (FontStyle)(FontStyle.Italic);

            }
            else if (checkBox3.Checked == true)
            {
                fStyle = (FontStyle)(FontStyle.Underline);

            }
            else
                fStyle = FontStyle.Regular;//普通文本
            textBox1.Font = new Font(textBox1.Font.FontFamily, textBox1.Font.Size, fStyle);
        
        }
        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            changeTextStyle();
        }

        private void checkBox2_CheckedChanged(object sender, EventArgs e)
        {
            changeTextStyle();
        }

        private void checkBox3_CheckedChanged(object sender, EventArgs e)
        {
            changeTextStyle();
        }
    }
}


本文转载:CSDN博客