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!!
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.
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
Re: Quick question about adding whitespace to a string
try looking into padright and padleft functions of string class
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.
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 :)
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.
Re: Quick question about adding whitespace to a string
Who said anything about a space class? :p
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...