如何选择C#按钮某些字符串,改变字体? [英] How to select certain string in c# button and change font?

查看:442
本文介绍了如何选择C#按钮某些字符串,改变字体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有文字按钮changeme的按钮。
如果我想是changeme的字体更改为40号,我如何做到这一点?

目前,我有这个code:

  button1.Font =新字体(button1.Font.FontFamily,40);


解决方案

我会建议创建一个子类的按钮类和重写的OnPaint 方法手动输出的文本。默认按钮类不支持此功能。

我会建议作进一步的研究,你检查出的<一个href=\"http://msdn.microsoft.com/en-us/library/system.windows.forms.visualstyles.visualstylerenderer.aspx\"相对=nofollow> VisualStyleRenderer 类将用于绘制按钮背景是有用的。可能有更简单的方法可以做到这一点避免重绘整个按钮,但使用VisualStyleRenderer不是特别繁重,并给你的灵活性的最大金额。

I have a button with text "button changeme". If i would like to change the font of "changeme" to size 40, how would i do so?

At the moment I have this code:

button1.Font = new Font(button1.Font.FontFamily, 40);

解决方案

I would recommend creating a sub-class of the Button class and overriding the OnPaint method to manually output the text. The default Button class does not support this functionality.

I would recommend for further research you check out the VisualStyleRenderer class which will be useful for drawing the button background. There may be easier ways to do this that avoid having to redraw the entire button, but using the VisualStyleRenderer is not particularly onerous, and will give you the greatest amount of flexibility.

这篇关于如何选择C#按钮某些字符串,改变字体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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