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,

Id rather display horizontal scroll bars only when they are needed, which will be rare. Im 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. Ive 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 ComboBoxs DropDownWidth property, probably the closest thing youll find. Youll probably want to compute the text length to find the maximum sized string. Heres 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 its bigger - that way you dont get a tiny drop down portion...

-Ner
 
Last edited by a moderator:
Thanks Nerseus,

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

Thanks,
Dan
 
It shouldnt be any larger when its not dropped down, but when dropped down it might overlay some other information. Its 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