当前位置:网站首页>C examples of using colordialog to change text color and fontdialog to change text font

C examples of using colordialog to change text color and fontdialog to change text font

2022-06-25 08:01:00 ykxxcs

c#ColorDialog Change the text color and FontDialog Example of changing text font

 Insert picture description here

 public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        // Display the color dialog ColorDialog
        private void button1_Click(object sender, EventArgs e)
        {

            DialogResult dr = colorDialog1.ShowDialog();
            // If color is selected , single click “ determine ” Button changes the text color of the text box 
            if (dr == DialogResult.OK)
            {
                textBox1.ForeColor = colorDialog1.Color;
            }
        }
        // Change text font and other dialog boxes FontDialog
        private void button2_Click(object sender, EventArgs e)
        {
            DialogResult dr = fontDialog1.ShowDialog();
            // If font is selected , single click “ determine ” Button changes the text font of the text box 
            if (dr == DialogResult.OK)
            {
                textBox1.Font = fontDialog1.Font;
            }
        }
    }
原网站

版权声明
本文为[ykxxcs]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/176/202206250626558783.html