Hi there,i´m having troubles trying to make just a part of my string to be in bold.

the code is:

String tudo = "";

    foreach (Ent_Proposta_Executada_Item item in neg_prop_exe.ItensProposta)
    {

        tudo +=   item.NumItem + " " + item.DescrItem.ToUpper() + "\n" + item.ConteudoItem + "\n";


    }

i want that the value item.DescrItem.ToUpper() to be in bold letters,could it be possible?

Recommended Answers

All 4 Replies

Which part would you like to make chages (bold text)?

Text like it self (string value) cannot be bold or anything. But you can change its visibility when passign it to some control, like textbox:

textBox1.Font = new Font(textBox1.Font, textBox1.Font.Style | FontStyle.Bold | FontStyle.Underline);

You have to use GDI API to draw the text. Learn/use the classes from System.Drawing namespace.

private void Form1_Load(object sender, EventArgs e)
{
    this.Paint += (sa, ea) =>
    {
     ea.Graphics.DrawString("Bold Text", 
                            new Font("Arial", 10f, FontStyle.Bold), 
                            Brushes.Black, 
                            new PointF(5, 5));
     };
}

But this is still has to do with controls (or form).
If you look into his code, he tries to change the text inside some loop of some string collection - impossible.

Depends how you are displaying it. If you display it in a richtextbox or as an html page then there are flag constructs for that. If you are displaying it in a console or some other 'dumb' display then no, you can't. If you REALLY need it to work in your 'dumb' display you will need to look into overriding the On_Paint() event and use GDI to do it yourself in the case of a winform app - this is not easily done in a console application. (This link describes setting colors of text in a windows console app)

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.