none
Bold part of string RRS feed

  • Question

  • How can i make part of string bold?

    string interval  = "Time = 45 sec";

    e.Graphics.Drawstring(interval,myFont,Brushes.Black,200,50)

    I want to bold only Time

    Tuesday, July 17, 2018 5:03 PM

All replies

  • Try a fragment like this:

    var s1 = "Time";

    var s2 = " = 45 sec";

    int x = 200;

    int y = 50;

    var g = e.Graphics;

    g.PageUnit = GraphicsUnit.Pixel;

    using( Font f2 = new Font( "Arial", 20f, GraphicsUnit.Point ) )

    {

           using( Font f1 = new Font( f2, FontStyle.Bold ) )

           {

                 var w1 = g.MeasureString( s1, f1 ).Width;

                 g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;

                 g.DrawString( s1, f1, Brushes.Black, x, y );

                 g.DrawString( s2, f2, Brushes.Black, x + w1, y );

           }

    }

     

    But you can also use two Label controls having different styles, or a borderless RichTextBox control, which has many formatting features.



    • Edited by Viorel_MVP Tuesday, July 17, 2018 6:03 PM
    Tuesday, July 17, 2018 6:02 PM
  • Hi Jordanhal,

    Welcome to the MSDN forum.

    What's your project type? It seems your issue is about the development and our forum is to discuss the VS IDE, we will help you move this thread to the appropriate forum for a more professional support, thank you for your understanding.

    Best regards,

    Sara


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Wednesday, July 18, 2018 7:02 AM
    Moderator
  • >>What's your project type? It seems your issue is about the development

    Just a question, and not to be rude, but... how does a top thread title of VISUAL STUDIO DEVELOPMENT lead anyone to the conclusion that this is an IDE forum only?

    Just curious if I am missing something...


    Thursday, July 19, 2018 10:43 PM