I'm not entirely certain you can... the font and such controls the entire string. That said, you can easily inherit from button and override the paint events, allowing you to draw your own text, though you'll also have to draw your own button as well.
Oooh! I just had a crazy idea... you could do something like this...
- public class TestButton : Button
-
{
-
public string FormattedText { get; set; }
-
-
protected override void OnPaint(PaintEventArgs pevent)
-
{
-
base.OnPaint(pevent);
-
-
Graphics g = pevent.Graphics;
-
-
// Draw formatted text here
-
}
-
}
As long as the button's text property is blank (which you can actually override and enforce), the only text that would appear would be your FormattedText string. You can use whatever you like there to control it, but if you used BBCode you could do something like...
- TestButton t = new TestButton();
-
t.FormattedText = "H{b}{u}E{/u}{/b}llo Or He{b}L{/b}lo";
(I used curly braces here 'cause the forum will convert my square brackets into formatted text inside the quote block.. *sigh* :D)
Then it'd just be a matter of parsing the string... something along the lines of...
- Font f = this.Font;
-
string formatStr = this.FormattedString;
-
string currText = "";
-
for (int i = 0; i < formatStr.Length; i++)
-
{
-
string currCode = "";
-
if (formatStr[i] = '[')
-
{
-
currCode = ...; // read until next ], figure out what the code is
-
}
-
-
if (currCode != "")
-
{
-
switch (currCode)
-
{
-
case "b":
-
f.Bold = true;
-
break;
-
case "/b":
-
f.Bold = false;
-
break;
-
...
-
}
-
}
-
else
-
{
-
currText += formatStr[i];
-
}
-
-
if (all our open tags have been closed)
-
{
-
g.DrawString(currText, f, new SolidBrush(this.ForeColor), x, y);
-
x += g.MeasureString(currText, f, ... whatever else this needs ...);
-
currText = "";
-
tagsOpened = false;
-
tagsClosed = false;
-
}
-
}
I guess y could be the position of the text centered on the button. For x, you'd need to find the position of the text centered on the button, then add to it as you built and drew your string.
Something like that... that's just an idea, don't take that code as complete. Hopefully it'll get you started though :)