Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formatting strings to "line up" in a label box or text box?

Status
Not open for further replies.

tommy19

Programmer
Aug 23, 2001
49
US
Hi there, I'm pretty sure there is a way to do this, but I can't remember how and I can't seem to find the answer anywhere.

ok, my output is a collection of strings, each string has individual parts that are different lengths, ie a company name is one section of the string, there are 5 different sections, but they are stored as 1 string. How can I get the output to "line up" even though the section lengths are different. And I need it in a label or textbox, not a file.

example output:

number -> 50001 comp ->'94' CONSTRUCTION CORP. name-> LARRY
number -> 170412500 comp -> FOSELLI CONSTRUCTION name-> " FOSELLI


 
I recently did the same kind of thing, and there's no really easy way to do it. My solution was to set the Font property of the text box to "Fixedsys", which is the system wixed width font. This makes every character the same width, so that now you can use the number of characters to measure the length of a string. Then, I just wrote a function that takes a string as input, and fits it to a certain number of characters, i.e. if I want a field width of 20 characters, it pads shorter strings with spaces or truncates longer ones. I also added an option to pad at the beginning or end of the string, so that you can get right or left justification. I can post the code if you want, but it's really ugly.
 
I've always used the fixed-pitch font solution like AdaHacker suggests.

The alternative was to write an owner-draw control to line them up, and I could never justify the time needed.

Chip H.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top