111,129
社区成员
发帖
与我相关
我的任务
分享
ColorDialog MyDialog = new ColorDialog();
// Keeps the user from selecting a custom color.
MyDialog.AllowFullOpen = false;
// Allows the user to get help. (The default is false.)
MyDialog.ShowHelp = true;
// Sets the initial color select to the current text color.
MyDialog.Color = rich_Input.ForeColor;
// Update the text box color if the user clicks OK
if (MyDialog.ShowDialog() == DialogResult.OK)
rich_Input.ForeColor = MyDialog.Color;
FontDialog fd = new FontDialog();//字体框
DialogResult d = fd.ShowDialog();//显示
if (d.Equals(DialogResult.OK))
{
if (rich_Input.SelectedText.Length == 0)//如果未选定,那么就修改全部
rich_Input.Font = fd.Font;
else
//修改选定的文本
rich_Input.SelectionFont = fd.Font;
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
for (int i = 1; i < 11; i++)
{
comboBox1.Items.Add(i * 8);
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
richTextBox1.Font = ChangeFontSize(richTextBox1.Font, int.Parse(this.comboBox1.Items[comboBox1.SelectedIndex].ToString()), GraphicsUnit.Pixel);
}
static public Font ChangeFontSize(Font font, float fontSize, GraphicsUnit unit)
{
if (font != null)
{
float currentSize = font.Size;
if (currentSize != fontSize)
{
font = new Font(font.Name, fontSize,
font.Style, unit,
font.GdiCharSet, font.GdiVerticalFont);
}
}
return font;
}
}
}
using System;