WINFORM学习手册——颜色选择框和字体选择框
我们在Form上新增两个按钮和一个文本输入框:
第一个按钮的单击事件:
/// <summary> /// 更改字体颜色 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, EventArgs e) { ColorDialog d = new ColorDialog(); if (d.ShowDialog() == DialogResult.OK) { this.textBox1.ForeColor = d.Color; } }
第二个按钮的单击事件:
/// <summary> /// 更改字体大小 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button2_Click(object sender, EventArgs e) { FontDialog d = new FontDialog(); if (d.ShowDialog() == DialogResult.OK) { this.textBox1.Font = d.Font; } }
显示效果: