|
-
February 27th, 2006, 09:39 AM
#1
Quick question about adding whitespace to a string
Hi everyone, I'm working on this project where I need to have tons of comboboxes with certain numbers and codes in them. Every one of these codes has a certain description and I would like to show them all this way:
"code | description"
Now, the problem with this is when the codes have different lengths. Usually it only differs one char, so I thought it was just a matter of adding a little check on the length of the code and then adding a blank in front of the "|" when the code had the shorter form, but the problem with this is that it just never alligns nicely. There will always be two or three pixels of difference between the length in front of the "|" for the shorter and the longer form of the code.
If anyone has any suggestions (adding a certain length of white pixels for example, although I think this might be a bit far fetched) or any other ways to display the codes and descriptions nicely, I'd be immensely greatful!
Thanks in advance!!
-
February 27th, 2006, 09:54 AM
#2
Re: Quick question about adding whitespace to a string
1) U can do "owner drawing" in ComboBox to achieve that (more to do but it can look very cool
2) U can use fixed pitch font like "Courier New" for example (easy way) and than U have to make all strings equal in count of characters.
Best regards,
Krzemo.
-
February 27th, 2006, 10:20 AM
#3
Re: Quick question about adding whitespace to a string
Just for interest sake, I think you can use the Space function, once you have determinde the length of the first string, to add spaces in front of the second string
-
February 27th, 2006, 01:06 PM
#4
Re: Quick question about adding whitespace to a string
try looking into padright and padleft functions of string class
-
February 28th, 2006, 03:17 AM
#5
Re: Quick question about adding whitespace to a string
Padding strings with spaces won't do you much good unless you're using a fixed-width font. This is exactly what you want.
-
February 28th, 2006, 06:19 AM
#6
Re: Quick question about adding whitespace to a string
Thank you all for the help! It took me a day or so to finetune the owner drawn combobox, but it looks great now, I'm glad I didn't go for the easy way :P
For those of you who are interested in this matter, I think this article is very useful too.
Thanks for the "Space" function too, I didn't know it existed and it sure is a lot easier to count the spaces in "Space(10)" then in
Last edited by hangman; February 28th, 2006 at 08:26 AM.
-
February 28th, 2006, 07:49 AM
#7
Re: Quick question about adding whitespace to a string
There is no Spaces class. Space is a function, specifically the Microsoft.VisualBasic.Strings.Space function.
-
February 28th, 2006, 08:28 AM
#8
Re: Quick question about adding whitespace to a string
Who said anything about a space class? 
I just tend to mix up those names, a space class would be quite silly I think, so it was even more silly of me not to see that I had written it wrong...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|