求助,怎么通过combobox控件来修改richtextbox的字体大小?

琴弦欲奏 2010-10-25 12:56:30
我正在编辑一个简单的文本编辑器
想要用combobox这个控件弄一些数字上去
然后点击可以改变richtextbox文本框上的字体大小
就好像QQ聊天对话框哪里的那种
给定数字,然后修改文字的大小
这个要怎么弄?
我是C#菜鸟
希望给位大侠回答能详细点
谢谢
...全文
345 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
laj0600310219 2010-10-25
  • 打赏
  • 举报
回复
还有下面这个是实现调整字体颜色的,一并给你贴出来吧,或许你也会用到:

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;
laj0600310219 2010-10-25
  • 打赏
  • 举报
回复
C#里面本身就自带有实现调节richtextbox控件字体大小的类,如下:

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;
}
亲爱的-爹爹 2010-10-25
  • 打赏
  • 举报
回复
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;
}
}
}
亲爱的-爹爹 2010-10-25
  • 打赏
  • 举报
回复
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;
}
}
}
亲爱的-爹爹 2010-10-25
  • 打赏
  • 举报
回复
哥我妥协了,Font.size为常量不能就这么改

111,129

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧