Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

i'm not lazy i'm just resting before i get tired.
  • *Experts*
Posted

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

Member, in good standing, of the elite fraternity of mentally challenged programmers.

 

Dolphins Software

  • *Experts*
Posted (edited)

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:

 

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

Edited by Nerseus
"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
  • *Experts*
Posted

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

Member, in good standing, of the elite fraternity of mentally challenged programmers.

 

Dolphins Software

  • *Experts*
Posted

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

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...