It been long time since i do some codes. so i forget the basic
What i want to do is that when i click on a (Bold or Italic) button the text on the RTB become bold and another click on that button the text go back normale.

Can some code this please ?

Thank you

3 Years
Discussion Span
Last Post by TekknoDraykko

Hello Quast:
First off I will say I'm a firm believer in allowing new coders to find their own solutions, with a little guidance; so I try not to give you the code I would use, but give you an outline or a template and let you take it from there. This way you can learn by doing.

That being said, there are a number of ways you can code this. The pattern I usually use is:

if(//text is not bold)
    //make text bold
    //make text un-bold

To do this you'd need to use the Font property of the string you want to check. Using a similar example if I wanted to change the color of a text when I click a button I might use the following code:

private void btnChangeColor_Click(object sender, EventArgs e)
    if (label1.ForeColor != Color.Red)
    //click and change the label color to red
    label1.ForeColor = Color.Red;
    //click again and change the color back
    label1.ForeColor = Color.Black;

There are probably more concise ways of achieving the same thing, but that is essentially the pattern that is used. Let me know if you have any questions.


This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.