(http://img142.imageshack.us/img142/5496/tbszh2.png)
As you can see from the pic, the text "overflows". Is this there a way to avoid this?
edit: an array / pointer thingy where to store the Strings while displaying a truncated version on the listbox is the first idea that popped up to my mind. I'm just checking it's not useless scripting before actually making it.
How would you like to avoid it? Can't you just not put such a long string into it? Or maybe change the font into a smaller one? Or even make the listbox wider? If you mean whether you could make the text break into two lines then no, with AGS' listboxes you can't do that. The whole idea of a listbox is to have one item on one row and each row equally high.
Quote from: bicilotti on Tue 26/02/2008 18:30:13
edit: an array / pointer thingy where to store the Strings while displaying a truncated version on the listbox is the first idea that popped up to my mind. I'm just checking it's not useless scripting before actually making it.
That sounds like a good workaround if you need the text to be that long.
Quote from: Pablo on Tue 26/02/2008 19:09:58
If you mean whether you could make the text break into two lines then no, with AGS' listboxes you can't do that. The whole idea of a listbox is to have one item on one row and each row equally high.
Fair enough. Thanks
Why not add a label beneath the listbox which shows the description of the currently selected level?
Quote from: GarageGothic on Tue 26/02/2008 19:28:25
Why not add a label beneath the listbox which shows the description of the currently selected level?
The list is typed in by the user and i need those strings later on, so no place for a label unfortunately. My idea is to use pointers to mirror the listbox, and cut the strings in that one at the xth characters.
I just meant that you could take the string for the currently selected item from the array and display it on a label. That way it wouldn't have to be cut.
I think what GG is getting at here is that you could put the items into the listbox in a truncated form such as, "D. text to dislpay plenty o..." and then display the "full-text" on a label beneath. You could use a function such as this to cut down the text and add the ellipses:
String TextToWidth(int width, FontType font, String text) {
if ((text == null) || (width <= 0) || (GetTextWidth(text, font) <= width) || (GetTextWidth("...", font) >= width)) return text;
String buffer = text.Substring(0, text.Length / 2); // starting with half the text gives us a nice starting position
while (GetTextWidth(buffer.Append("..."), font) > width) { // shorten text
buffer = buffer.Truncate(buffer.Length - 1); // remove one character
}
while (GetTextWidth(buffer.Append("..."), font) < width) { // we can still add more
buffer = buffer.AppendChar(text.Chars[buffer.Length]); // add one character
}
if (GetTextWidth(buffer.Append("..."), font) > width) buffer = buffer.Truncate(buffer.Length - 1);
return buffer.Append("...");
}
// while setting the listbox items:
lstList.AddItem(TextToWidth(userinput));
internalArray[lstList.ItemCount - 1] = userinput; // store the original input in an array
// select the item
lblLabel.Text = internalArray[lstList.SelectedIndex];
It's untested and that's definitely some pseudo-code at the end, but perhaps you could use something like this? I've used a similar concept before with regard to truncating the text and adding an ellipsis (...).
Found a shorter path for lazy folks like me:
ListBox2 = where the items will be stored, invisible
ListBox4 = where they will be showed, visible
//fake listbox, to be placed in rep_ex
int c = 0;
ListBox4.Clear();
while(c < ListBox2.ItemCount)
{
ListBox4.AddItem(ListBox2.Items[c].Truncate(30));
c++;
}