Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / July 2006

Tip: Looking for answers? Try searching our database.

How to resize combobox?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
dfetrow410@hotmail.com - 04 Jul 2006 11:43 GMT
How to I resize the combobox and set it a bit passed the largest string
in the box. By the way, the box gets built by a db table. Thanks for
your help

Dave
Stoitcho Goutsev (100) - 04 Jul 2006 14:57 GMT
Dave,

You can change the width of the combobox via its Size property, but you
cannot change the height of the combobox. The width depend on the font used
to print the items. The bigger the font, the taller the combobox.
If you want to have control over the combobox height you need to implement
owner-draw combobox. In this case you can set the ItemHeight property.

If you want change the width of the combobox depending on the lenght of the
text you can measure the text using a graphics object created from the
combobox control. You need to take into cosideration the pull-down button. I
believe it is related to the size of the scroll bart thus you can use
SystemInformation.VerticalScrollBarWidth.

Signature

HTH
Stoitcho Goutsev (100)

> How to I resize the combobox and set it a bit passed the largest string
> in the box. By the way, the box gets built by a db table. Thanks for
> your help
>
> Dave
Joris Zwaenepoel - 05 Jul 2006 09:32 GMT
Try this:

   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

       With ComboBox1.Items
           .Clear()
           .Add("AAA")
           .Add("BBBBBB")
           .Add("CCCCCCCCC")
           .Add("DDDDDDDDDDDD")
           .Add("EEEEEEEEEEEEEEE")
           .Add("WWWWWWWWWWWWWWWWWWWWWW1")
       End With

       With ComboBox1
           Dim g As Graphics = ComboBox1.CreateGraphics
           Try
               For index As Integer = 0 To .Items.Count - 1
                   Dim size As SizeF = g.MeasureString(.Items(index), .Font)
                   size.Width += SystemInformation.VerticalScrollBarWidth
                   If .Width < size.Width Then .Width = size.Width
               Next
           Finally
               g.Dispose()
           End Try
       End With

   End Sub

I hope this helps,

Joris

> How to I resize the combobox and set it a bit passed the largest string
> in the box. By the way, the box gets built by a db table. Thanks for
> your help
>
> Dave

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.