Hi

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

Hi

Have a look at the SelectionFont property, this will allow you to set the font to bold for either the selected text, or any text after the insertion point.

HTH

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
else
    //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;
    }
    else
    {
    //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.

Tekkno

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.