Results 1 to 7 of 7

Thread: add txt to a new line in a label

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2002
    Posts
    5

    add txt to a new line in a label

    Hello, I am trying to display log information to the user from the database. It works fine my only problem is that I cannot find a way to control how it looks. I have the log data output to one sting that I put together in a loop. I am only using one label to display it all (about 8 – 15 entries). Is there a way to put a new line into a label filed so I can append the data to a new line? If that makes any sense.
    Thanks

  2. #2
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Lancashire UK
    Posts
    375

    Re: add txt to a new line in a label

    Try using a textbox with multiline set to true instead of a label, and as you add a new line to the text insert a line feed 'vbcrlf'

  3. #3
    Fanatic Member
    Join Date
    Aug 2006
    Location
    Chicago, IL
    Posts
    514

    Re: add txt to a new line in a label

    No, don't do that. vbCrLf is outmoded.

    You can use a stringbuilder with the AppendLine() function, then send that back to the label like this:

    VB Code:
    1. Dim myStringBuilder As New System.Text.StringBuilder
    2.  
    3. myStringBuilder.AppendLine(string goes here)
    4.  
    5. Label1.Text = myStringBuilder.ToString()
    Warren Ayen
    Senior C# Developer
    DLS Software Studios (http://www.dlssoftwarestudios.com/)

    I use Microsoft Visual Studio 2005, 2008, working with Visual Basic and Visual C#
    Hey! If you like my post, or I solve your issue, please Rate Me!

  4. #4

    Thread Starter
    New Member
    Join Date
    Sep 2002
    Posts
    5

    Re: add txt to a new line in a label

    Thank you both for your help. I would perfer to use the second method but it soesnt seem to put the data onto a new line it still shows up like this:

    Code to make string
    Dim result As New System.Text.StringBuilder
    While DataReader.Read()

    Result.AppendLine(DataReader("test_data"))
    End While
    Label.Text = result

    Results look like this:

    'Successfully Renamed and moved 00007665.jpg to 5-05-072-11 09-Sep-2005.jpg' 'Successfully Renamed and moved 00007665.jpg to 5-05-072-11 09-Sep-2005.jpg' 'Successfully Renamed and moved 03vvt2kt.tif to PLA1900.tif' 'Successfully Renamed and moved 03vvt2kt.tif to PLA1900.tif' 'Successfully Renamed and moved 1xpbazcg.tif to EZE860013.tif' 'Successfully Renamed and moved 1xpbazcg.tif to EZE860013.tif' 'Successfully Renamed and moved 2xvuaibv.tif to MSL3078.ti

    there should be a new line at each "'Successfully "

    Thanks again

  5. #5
    Fanatic Member
    Join Date
    Aug 2006
    Location
    Chicago, IL
    Posts
    514

    Re: add txt to a new line in a label

    Yes, there should be a new line. My test worked, for me

    Make sure the label isn't autosizing.

    also, change it to Label.Text = Result.ToString()
    Warren Ayen
    Senior C# Developer
    DLS Software Studios (http://www.dlssoftwarestudios.com/)

    I use Microsoft Visual Studio 2005, 2008, working with Visual Basic and Visual C#
    Hey! If you like my post, or I solve your issue, please Rate Me!

  6. #6
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: add txt to a new line in a label

    Actually you can do it with simple string concatenation as well, as long as you aren't working with extremely large strings... and I would use Environment.Newline instead of vbcrlf...
    VB Code:
    1. Label1.Text = "This is the first line" & Environment.NewLine & "This is the second line"

  7. #7

    Thread Starter
    New Member
    Join Date
    Sep 2002
    Posts
    5

    Re: add txt to a new line in a label

    Great... works great thanks for the help

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