Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Autosize Drop Down 1

Status
Not open for further replies.

myrgir

Programmer
Feb 7, 2006
62
CA
Hi
I have a combo box that I would like to autosize the dropdown.
Is there any way I can do this?
 
Check out this link:

Windows Forms FAQ

Look for question/answer 21.7

The example is in C#, but it is pretty straightforward and should be easy to convert to VB.

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
Hi
two lines I don't know how to convert to vb
System.Drawing.Graphics g = comboBox1.CreateGraphics();

and

float w = g.MeasureString(o.ToString(), comboBox1.Font).Width;

Somebody can help me with this?
 
Sorry, I was pressed for time yesterday. Here's the whole thing in VB:

Dim g As System.Drawing.Graphics = ComboBox1.CreateGraphics
Dim maxWidth As Double = 0.0F
For Each o As Object In ComboBox1.Items
Dim w As Double = g.MeasureString(o.ToString(), ComboBox1.Font).Width
If (w > maxWidth) Then
maxWidth = w
End If
Next

g.Dispose()
ComboBox1.[red]DropDownWidth[/red] = maxWidth + 20

Note the portion in red. As the code was written (using .Width instead of .DropDownWidth), it would increase the size of the combobox control. This change only affects the width of the dropdown box.

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top