Solved

How do I add a vertical scroll bar to a label ?

Posted on 2004-10-21
605 Views
Last Modified: 2010-04-15
I am outputting data to a label in a Windows App using C#.  Some of the data is rather long and cuts off at the bottom of the label.  How can I add a vertical scroll bar to it?

ptslv
0
Question by:ptslv
    10 Comments
     
    LVL 69

    Accepted Solution

    by:
    Scrollbars belongs to TextBox and not to Label.

    Use a ReadOnly textbox instead.
    0
     

    Author Comment

    by:ptslv
    OK, emoreau.  I got the textbox working with the scroll bar, but now my output has lost it's formatting.  How do I get the line returns back?

    ptslv
    0
     
    LVL 69

    Expert Comment

    by:Éric Moreau
    is your Multiline property set to True?
    0
     

    Author Comment

    by:ptslv
    yes
    0
     
    LVL 69

    Expert Comment

    by:Éric Moreau
    Then you surely don't have real carriage return into your string.
    0
     

    Author Comment

    by:ptslv
    I am using "\n" in the string.
    0
     
    LVL 69

    Expert Comment

    by:Éric Moreau
    try replacing \n with environment.newline
    0
     

    Author Comment

    by:ptslv
    emoreau-

    I tried using "\r".  It trashes the formatting in the label and doesn't do any better in the textbox.

    ptslv
    0
     
    LVL 69

    Expert Comment

    by:Éric Moreau
    use this:

    textBox1.Text = "line 1\nline2\nline3".Replace("\n",Environment.NewLine);
    0
     

    Author Comment

    by:ptslv
    emoreau,

    I went back thru and replaced all the "\r" with Environment.NewLine and it worked like a charm.  Thanks!

    ptslv
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

     Java Android Coding Bundle

    Whether you're an Apple user or Android addict, learning to code for the Android platform is an extremely valuable, in-demand skill. It all starts with Java, the language behind the apps and games that make Android the top platform it is today.

    Suggested Solutions

    Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
    Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
    This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…

    934 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now