Question

I have multiple strings with the same length, but they appear to need a different amount of tabstops to format properly. I am unsure on what too google for and I haven't gotten any results that would have helped me so I am asking here.

What would be a good solution for this other than creating multiple controls, which I do not want...

Look at Malzahar and Kassadin ( same length, same amount of tabstops, malzahar's format is messed up ) Current code:

if (_counter.zCounter[i].Length <= 8)
{
    DataCollection += _counter.zCounter[i] + "\t\t↑" + _counter.zUpvotes[i] + "\t↓" + _counter.zDownvotes[i] + "\n";
}
else
    DataCollection += _counter.zCounter[i] + "\t↑" + _counter.zUpvotes[i] + "\t↓" + _counter.zDownvotes[i] + "\n";
Was it helpful?

Solution

A strings Length (number of characters) is only loosely related to its Width (number of pixels).

Your approach will only work with fixed-width fonts (like Courier). Otherwise, you would need to use a Measure() function and compute the spaces/tabs for a specific font. Messy.

Much better to change your GUI to have 2 columns.

OTHER TIPS

Are working with a fixed-width (monospace) font? Even then the placement of tabs depends on the lengths of your strings.

When a string preceding a tab is too long, you need less tabs. That's where your problem comes from:

str→   →   →str
strstr→→   →str
strstrstr→ →   →str

I recommend you insert padding spaces instead. You can calculate the number of spaces like this:

padding = (column - (index % column)) % column

Where column is the zero-based column to which to want to align the next word, and index is the zero-based index of the character just after the previous word.

str·········str
strstr······str
strstrstr···str
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top