Link to home
Start Free TrialLog in
Avatar of steveuci
steveuci

asked on

Columnized Textbox in VB6?

Ok, the challenge is to take a big block of text and *neatly* divide it up amongst two columns displayed onscreen.   By neatly, I mean putting as many words of a non-monospaced font as possible in the left column and putting the remainder in the right column.

As it is, I have to set a *guesstimate* of X # of characters before I cut it off and put the rest of the text on the 2nd column, and since the font is not monospaced, this results in unsightly division of text between columns.   The text can be anything which is why my guesstimate solution is not good, and sometimes results in the following:

Hello, blah blah blah blah blah        blah blah blah blah blah blah
blah blah blah blah blah blah          blah blah.
blah blah blah blah blah blah
blah blah

When it should be neater, like this:

Hello, blah blah blah blah blah        blah blah blah blah.
blah blah blah blah blah blah          
blah blah blah blah blah blah
blah blah blah blah blah blah

FYI, right now I'm using two labels for the two columns.   For my application it will always be just two columns.   I don't need to use labels if some other intrinsic control will work, a flexgrid or textbox or listbox will work if there's some trick I could do with those.    The only requirements are that this must be done without 3rd party controls, in VB6, and I need to be able to set the backcolor to any color as well as get rid of borders so that it blends in with the rest of the form.

I've thought about using the Label Autosize feature to test how much text I've got in one label, and if the height of the label exceeds what I know is reasonable for that one column, start pulling text into the next column (label).  However, autosize just sticks all the text in one line, so this doesn't work.

Thanks for your time!
Avatar of sirbounty
sirbounty
Flag of United States of America image

Have you tried it this way:

Text1.text=Label1.Caption & space(39-len(label1.caption) & label2.caption

?
Missed a paren:

Text1.text=Label1.Caption & space(39-len(label1.caption)) & label2.caption
Avatar of steveuci
steveuci

ASKER

Thanks for responding so quickly sirbounty.  However, I'm not sure I understand your suggestion, so perhaps I wasn't clear enough.   I'm pulling a chunk of text from a database to display.  This text is oftentimes long enough that needs to be divided up into two columns, but with as much text as possible in the left column.

Your suggestion almost sounds like it depends upon a monospaced font and assumes textboxes have column capability built in?   Let me know what you mean, and thanks!
Hmm..guess I read the Q incorrectly...
I don't know of a way to accomplish what you're after...sorry. :(
ASKER CERTIFIED SOLUTION
Avatar of Dabas
Dabas
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
sometimes right?
You might come accross a case like below

Hello, blah blah blah blah blah        blahblahblah blah blah blah
blah blah blah blah blah blah          blah blah.
blah blah blah blah blah blah
blah blah blah blah

here blahblahblah dosent fit in the first column, so obvoiusly it moves on to the next column

Another solution
suppose the first cloumn takes x characters, take a pivot to that length,
and then split the sting to the closest space before that position
i think this should work
Dabas, thank you for bringing the TextWidth method to my attention -- that completely solves all of my problems.   Now, with your tip, I am using a hidden PictureBox control to determine when a string of tokens is going to exceed the width of a listbox, and then just go to the next line and process tokens from there, and when the # of visible lines in the current column is exceeded, start working on the next listbox/column.

Thanks to everyone that responded!
Steveuci:
Looks like you found a nice and elegant solution!

Dabas