7 Replies - 4698 Views - Last Post: 05 October 2012 - 10:46 AM Rate Topic: -----

#1 EntIam  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 04-October 12

How can I format text in a multi line textbox?

Posted 04 October 2012 - 06:12 PM

I am currently using vbtab to format text that will be displayed in a multiline text box. The first tiem which is the name of building materials will throw off the alignment of everything in the textbox if it is too long. Someone suggested that I use string.format but I don't see how to use it besides for number or if it is possible. Here is the code I am currently using to try to format the text with vbtab.

 txtOutPut.Text = txtOutPut.Text & strItem & vbTab & vbTab & intQuantity & vbTab & vbTab & decPrice & vbTab & vbTab & decSubTotal & ControlChars.NewLine 


Is This A Good Question/Topic? 0
  • +

Replies To: How can I format text in a multi line textbox?

#2 November-06  Icon User is offline

  • D.I.C Regular

Reputation: 46
  • View blog
  • Posts: 391
  • Joined: 04-January 11

Re: How can I format text in a multi line textbox?

Posted 04 October 2012 - 06:27 PM

Hi, there's a thread in C# that talks about using String.Format to apply alignment. You can use the same format in VB.Net

In Curtis Rutland's post in that thread, he gave this link as a reference:

http://blog.stevex.n...ting-in-csharp/

Even if you don't know C#, the site will still be of use to you since the same string.Format is used in VB.Net

If you are interested in reading that thread, here's the link:

http://www.dreaminco...ication-tables/

If the first URL helps you, kindly vote Curtis Rutland's post in the C# thread to give credit to the one who originally gave this link.

This post has been edited by November-06: 04 October 2012 - 06:30 PM

Was This Post Helpful? 1
  • +
  • -

#3 EntIam  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 04-October 12

Re: How can I format text in a multi line textbox?

Posted 05 October 2012 - 07:10 AM

Thank you for the quick response. I was unable to look as quickly. I am reviewing the links now. The other post does indeed seem to be very close to what I need to do.
Was This Post Helpful? 0
  • +
  • -

#4 lucky3  Icon User is offline

  • Friend lucky3 As IHelpable
  • member icon

Reputation: 231
  • View blog
  • Posts: 765
  • Joined: 19-October 11

Re: How can I format text in a multi line textbox?

Posted 05 October 2012 - 08:05 AM

If your strItems vary in length a lot, then you'll get output, that will not be aligned in columns. For doing it so, you might want to look at solutions in pyramid challenge. Basic idea is to get the number of characters in longest line/column, and insert the needed amount of " "(space characters) in front of shorter "cells" in each row, so the final result is the same length of string for each entry.
Was This Post Helpful? 1
  • +
  • -

#5 EntIam  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 04-October 12

Re: How can I format text in a multi line textbox?

Posted 05 October 2012 - 09:32 AM

That makes sense. The program is going to have a combobox with building materials the user can select from. The user then enters the quantity they need and the price per item. Someone suggested that I should be using a grid instead of a text box. I am unfamiliar with grids. Would making a grid with the items column long enough to fit the longest material name work well? I have never worked with grids, and they seem complicated (at least for me). I would ideally like set columns. It seems like that would avoid this whole problem I am having.

I am trying to understand the link you provided. The code is written to determine how many spaces need to be added to each number by comparing it to the another number? I have trouble looking at code and determining what is going on still.
Was This Post Helpful? 0
  • +
  • -

#6 lucky3  Icon User is offline

  • Friend lucky3 As IHelpable
  • member icon

Reputation: 231
  • View blog
  • Posts: 765
  • Joined: 19-October 11

Re: How can I format text in a multi line textbox?

Posted 05 October 2012 - 09:47 AM

The DataGridView would be way better solution, really. Or ListView. Depends on what you want to do. TextBox (or RichTextBox) is really not suitable for displaying and selecting data in easy way. With DataGridView or ListView, you can forget all the mess with adding extra spaces. I linked to the challenge just in case, you absolutely must use TextBox (like in case you are attending some class or something, and you are required to).
Was This Post Helpful? 1
  • +
  • -

#7 EntIam  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 04-October 12

Re: How can I format text in a multi line textbox?

Posted 05 October 2012 - 10:36 AM

This is for a VB class. He said he has no preference on how we program it just as long as it does what he wants. So I can use any object, I am just only familar with textboxes and labels. I have very little experience with listboxes and no experience with grids. This program has me rather frustrated. Pad left seems to work but leaves a huge space on the left, which I dislike. It is all building materials that will be listed first and some are rather long.

 txtOutPut.Text = txtOutPut.Text & strItem.PadLeft(15) & intQuantity.ToString.PadLeft(15) & decPrice.ToString.PadLeft(15) & decSubTotal.ToString.PadLeft(15) & ControlChars.NewLine 


Everything is aligned with this but I dislike the large space. I have not checked to see if it remains aligned when saved to a text file which is one of the requirements.
Was This Post Helpful? 0
  • +
  • -

#8 EntIam  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 04-October 12

Re: How can I format text in a multi line textbox?

Posted 05 October 2012 - 10:46 AM

View PostEntIam, on 05 October 2012 - 10:36 AM, said:

This is for a VB class. He said he has no preference on how we program it just as long as it does what he wants. So I can use any object, I am just only familar with textboxes and labels. I have very little experience with listboxes and no experience with grids. This program has me rather frustrated. Pad left seems to work but leaves a huge space on the left, which I dislike. It is all building materials that will be listed first and some are rather long.

 txtOutPut.Text = txtOutPut.Text & strItem.PadLeft(15) & intQuantity.ToString.PadLeft(15) & decPrice.ToString.PadLeft(15) & decSubTotal.ToString.PadLeft(15) & ControlChars.NewLine 


Everything is aligned with this but I dislike the large space. I have not checked to see if it remains aligned when saved to a text file which is one of the requirements.



I realized as soon as I pressed add reply that I could padright instead of padleft which gets rid of the space on the left.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1