How to select certain string in c# button and chan

2019-08-29 09:23发布

问题:

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);

回答1:

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.



回答2:

I would recommend you to use this code it may help you to solve this issue.Please try this code :

this.button1.Font = new System.Drawing.Font("Microsoft Sans Serif", 15F);