By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,191 Members | 2,190 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,191 IT Pros & Developers. It's quick & easy.

Changing the Font to Bold

P: n/a
I found some code to change the font on a button to bold:

private void btnBold_Click(object sender, System.EventArgs e)

{

btnCalculate.Font = new Font(btnCalculate.Font,

btnCalculate.Font.Style | FontStyle.Bold);

}

everything is cool. It works. I then wanted to change the font back to
normal:

private void btnNormal_Click(object sender, System.EventArgs e)

{

this.btnCalculate.Font = new Font(btnCalculate.Font,

btnCalculate.Font.Style | FontStyle.Regular);

}

It doesn't work. Why can't I change the font back to Normal?

Thank you.
Jul 31 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Henry Jones wrote:
I found some code to change the font on a button to bold:

private void btnBold_Click(object sender, System.EventArgs e)

{

btnCalculate.Font = new Font(btnCalculate.Font,

btnCalculate.Font.Style | FontStyle.Bold);

}

everything is cool. It works. I then wanted to change the font back to
normal:

private void btnNormal_Click(object sender, System.EventArgs e)

{

this.btnCalculate.Font = new Font(btnCalculate.Font,

btnCalculate.Font.Style | FontStyle.Regular);

}

It doesn't work. Why can't I change the font back to Normal?

Thank you.

In the statement:

btnCalculate.Font = new Font(btnCalculate.Font
btnCalculate.Font.Style| FontStyle.Bold);

you are using "|" operation btnCalculate.Font.Style| FontStyle.Bold,
which added the Bold style of the original style ( I assume it is normal).

And then again, in the second function, this.btnCalculate.Font = new
Font(btnCalculate.Font, btnCalculate.Font.Style | FontStyle.Regular);
you are doing another "|" operation, which takes no effect. Since
Font.Style is already FontStyle.Regular|FontStyle.Bold.

I will do this instead:
private void btnBold_Click(object sender, System.EventArgs e)
{
btnCalculate.Font = new Font(btnCalculate.Font, FontStyle.Bold);

}
private void btnNormal_Click(object sender, System.EventArgs e)

{

this.btnCalculate.Font = new Font(btnCalculate.Font,FontStyle.Regular);

}
Jianwei
Aug 1 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.