36.winform之字体对话框和颜色对话框
效果
实现
代码
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 WindowsFormsApp6 {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
/// <summary>
/// 当点击时弹出字体对话框
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, EventArgs e) {
FontDialog fontDialog = new FontDialog();
fontDialog.ShowDialog();
//把在对话框中选中的字体赋值给文本框的字体
textBox1.Font = fontDialog.Font;
}
/// <summary>
/// 弹出颜色对话框
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button2_Click(object sender, EventArgs e) {
ColorDialog colorDialog = new ColorDialog();
colorDialog.ShowDialog();
//把在对话框中选择的颜色赋值给文本框中文本的颜色
textBox1.ForeColor = colorDialog.Color;
}
}
}