Solved

Columnized Textbox in VB6?

Posted on 2004-03-26
8
418 Views
Last Modified: 2012-06-21
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!
0
Comment
Question by:steveuci
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 10692598
Have you tried it this way:

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

?
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 10692599
Missed a paren:

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

Author Comment

by:steveuci
ID: 10692617
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!
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 10692761
Hmm..guess I read the Q incorrectly...
I don't know of a way to accomplish what you're after...sorry. :(
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 27

Accepted Solution

by:
Dabas earned 250 total points
ID: 10696455
Hi steveuci:
Have you considered ListViews in Report View Style?

You might also want to read the following on the TextWidth function which should help you finding the exact width even if not monospaced is used

TextWidth Method
     

Returns the width of a text string as it would be printed in the current font of a Form, PictureBox, or Printer. Doesn't support named arguments.

Syntax

object.TextWidth(string)

The TextWidth method syntax has these parts:

Part Description
object Optional. An object expression that evaluates to an object in the Applies To list. If object is omitted, the Form with the focus is assumed to be object.
String Required. A string expression that evaluates to a string for which the text width is determined. Parentheses must surround the string expression.


Dabas
0
 
LVL 3

Expert Comment

by:bvRocks
ID: 10704163
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
0
 

Author Comment

by:steveuci
ID: 10708163
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!
0
 
LVL 27

Expert Comment

by:Dabas
ID: 10708248
Steveuci:
Looks like you found a nice and elegant solution!

Dabas
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

747 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

12 Experts available now in Live!

Get 1:1 Help Now