ComboBox Scrollbars

hmmm good question....
have you considered a tool tip instead?
you could show the tool tip whenever the word is too big
just an idea
 
Hi Brandon,

I'd rather display horizontal scroll bars only when they are needed, which will be rare. I'm finishing the conversion calculator portion of my project and the telecommunications catagory presented some very long, lengthy items (does that say something about hardware guys?). This is the only catagory that presents this problem. I've used tool tips for explaining entry error corrections to the user, so that idea is out, or maybe not if there is no way of doing this.

Thanks
Dan
 
You can set the ComboBox's DropDownWidth property, probably the closest thing you'll find. You'll probably want to compute the text length to find the maximum sized string. Here's a C# code sample that may work for you:

C#:
comboBox1.Items.Add("hello world");
comboBox1.Items.Add("blah");
comboBox1.Items.Add("Show me a sane man and I will cure him for you");

Graphics g = comboBox1.CreateGraphics();
float maxSize = -1f;
SizeF size = new SizeF();
foreach(object o in comboBox1.Items)
{
	size = g.MeasureString(o.ToString(), comboBox1.Font);
	if(size.Width > maxSize) maxSize = size.Width;
}
g.Dispose();

comboBox1.DropDownWidth = (int)maxSize;

You could check the maxSize against the current control Width and only set the DropDownWidth if it's bigger - that way you don't get a tiny drop down portion...

-Ner
 
Last edited:
Thanks Nerseus,

I've pretty much already maxed the comboxes length in relation to the form size. But, your idea might work okay. I'll give it a try and see how it shows in relation to the other controls near the combo box.

Thanks,
Dan
 
It shouldn't be any larger when it's not dropped down, but when dropped down it might overlay some other information. It's still better than the technique I used in VB3 where we made the whole control wider while dropped down, then shrink when closed - very nasty looking :)

-Nerseus
 
Back
Top