user1920206
user1920206

Reputation: 69

How to select certain string in c# button and change font?

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

Upvotes: 0

Views: 1117

Answers (2)

Asif Rashid
Asif Rashid

Reputation: 15

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

Upvotes: 0

Brett Wolfington
Brett Wolfington

Reputation: 6627

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.

Upvotes: 4

Related Questions