更改所选文字的字体 [英] Change a font of selected text

查看:99
本文介绍了更改所选文字的字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在文本框中设置所选文本的字体大小?


谢谢!

How to set font size of selected text in textbox?


Thanks!

推荐答案

您不能. TextBox有一个FontSize属性,这就是字体的大小.如果要更改所选文本的大小,我想您将不得不使用RichText控件.
You can''t. The TextBox has a FontSize property, and that''s what size the font is. If you want to change the size of selected text, I think you''re going to have to fiddle around with a RichText control.


如果您非常想使用TextBox. ..让我们说您的宗教禁止您使用任何带有Rich单词的东西,或者RichTextBox可能以某种方式亲自冒犯了您.

然后,您将不得不使用子类覆盖Paint事件,并根据需要绘制文本.当然,此方法会花费很多工作,并且已经在RichTextBox中为您完成了...但是,嘿,也许您真的不喜欢它.
If you badly want to use a TextBox...let''s say your religion bans you from using anything with the word Rich in it or maybe the RichTextBox has personally offended you in some way.

Then, you would have to overwrite the Paint event using subclassing and draw the text as you want it. Of course, this method would take a lot of work and is already done for you in the RichTextBox...but hey, maybe you just really don''t like it.


您好,josip
这是一个很贴切的答案,可能会导致您找到完美的解决方案
如果我有时间,我将尝试重写它,并尝试为您提供确切的答案(如果可以的话),请告诉我

遵循该程序
使用系统;
使用System.Collections.Generic;
使用System.ComponentModel;
使用System.Data;
使用System.Drawing;
使用System.Linq;
使用System.Text;
使用System.Windows.Forms;
命名空间twoAFont
{
公共局部类Form1:Form
{
字体myFontBig,myFontSmall;
FontStyle styleBld,styleReg;
//图形gg = base.CreateGraphics();

公共Form1()
{
InitializeComponent();
myFontBig = new Font("Andaluse",16,styleBld);
myFontSmall = new Font("Andaluse",10,styleReg);
}
private void button1_Click(对象发送者,EventArgs e)
{
//字符串s1,s2;
图形gg = textBox1.CreateGraphics();
TextRenderer.DrawText(gg,"Hellow Mr. Josip",myFontBig,
新Point(100,50),SystemColors.GradientActiveCaption);
TextRenderer.DrawText(gg,"Hellow OutLaw,我是你的朋友khalid sabtan,记住英语不是我的母语,所以在某些情况下,我不得不忽略某些单词,将来我会变得更加饱满.",myFontSmall,
新Point(10,50),SystemColors.GradientActiveCaption);
}
}
}
Hi josip
this is a close answer that could lead you to your perfect solution
if i have time i will try to rewrite it and try to provide you exact answer (if i could) let me know

follow this program
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 twoAFont
{
public partial class Form1 : Form
{
Font myFontBig, myFontSmall;
FontStyle styleBld, styleReg;
//Graphics gg = base.CreateGraphics();

public Form1()
{
InitializeComponent();
myFontBig = new Font("Andaluse", 16, styleBld);
myFontSmall = new Font("Andaluse", 10, styleReg);
}
private void button1_Click(object sender, EventArgs e)
{
//string s1, s2;
Graphics gg = textBox1.CreateGraphics();
TextRenderer.DrawText(gg, "Hellow Mr Josip", myFontBig,
new Point(100, 50), SystemColors.GradientActiveCaption);
TextRenderer.DrawText(gg, "Hellow OutLaw i am your friend khalid sabtan remember english is not my native languge so in certain case i have to ignore some words i will be carfull in future Bye", myFontSmall,
new Point(10, 50), SystemColors.GradientActiveCaption);
}
}
}


这篇关于更改所选文字的字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆