Results 1 to 11 of 11

Thread: [2.0] Easy question on a Label

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Location
    Madrid
    Posts
    325

    [2.0] Easy question on a Label

    Hi,
    Just say I´d like this string:

    Code:
    string text = "Hello my friend";
    Added to a label;

    Code:
    label1.text = text;
    Now say, I´d like to format part of the string, bold.

    How can I go about doing this? This is C# Winforms.

    Thanks!.

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Location
    Madrid
    Posts
    325

    Re: [2.0] Easy question on a Label

    Hi, I´d also like to know how to add or append a string to the lable, with a certain indentation, or padding,...

    Thanks,..!
    Last edited by Rauland; May 11th, 2007 at 05:54 AM. Reason: mistype

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Location
    Madrid
    Posts
    325

    Re: [2.0] Easy question on a Label

    for the margin I´ve added:

    "\t" + "Some text", but It doesn´t like it either,..

  4. #4
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2.0] Easy question on a Label

    The Label doesnt support formatting parts of the text, you can either make all the text bold or none of it.
    And to append text to a label:
    C# Code:
    1. Label1.Text += "hello";
    Last edited by Atheist; May 12th, 2007 at 05:23 AM.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Location
    Madrid
    Posts
    325

    Re: [2.0] Easy question on a Label

    Hi, thanks for the reply,
    How can I make all of it bold from code?

    For instance:

    Code:
    String text = "Hello";
    
    Label1.Text += text;
    HOw would you make text bold?

  6. #6
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2.0] Easy question on a Label

    C# Code:
    1. label1.Font = new Font(label1.Font, FontStyle.Bold);
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  7. #7
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: [2.0] Easy question on a Label

    Also i would watch using words like Text i don't believe it is a reserved word in C# but some words are.

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Location
    Madrid
    Posts
    325

    Re: [2.0] Easy question on a Label

    Thanks Atheist,Hell-Lord,

    I still find it quite annoying that I can´t format part of the text bold, and parts of the text with an indentation,..

    Any more sugestions?

  9. #9
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2.0] Easy question on a Label

    Sounds like you need to use a RichTextBox to show your text. It allows you to format the text in any way you want. If you only want to display information in it and not let it be edit-able, set the ReadOnly property to True.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Location
    Madrid
    Posts
    325

    Re: [2.0] Easy question on a Label

    Hi thanks, Atheist,
    I´ll have a look,..
    Last edited by Rauland; May 13th, 2007 at 05:35 AM.

  11. #11
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] Easy question on a Label

    Use GDI+ to draw your string directly onto your form. Then you have complete control over every character. You can have each character in a different font, some bold, some underlined, etc., etc.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width