Autosize Combobox in ToolStrip

  • Thread starter VBTricks.de.vu Webmaster
  • Start date
V

VBTricks.de.vu Webmaster

Hello,

I'm still reimplementing the GUI of my app using the new toolstrips. My
current problem is to autosize a combobox to the available with in the
parent toolstrip. There are some buttons left and right of the
controlhost which contains the combobox. The right buttons are
rightaligned and I now want to fill the available space between the left
buttons and right ones with the combobox. But I can't find a fitting
property and changing the combobox with in a resize-event-handler for
the toolstrip does not seem to work, as when I'm scaling down the
toolstrip, the combobox is hidden (and displayed in the dropdown menu)
as it's too large.
Anyone out there able to help me?


Thanks in advance,

Stefan

--
___________________________________www.VBTricks.de.vu
the free resource for Visual Basic, Gambas and Pascal
components, tips & complete projects

www: http://www.VBTricks.de.vu
mail: vbtricks <at> gmx <dot> net
_____________________________________________________
 
K

Ken Tucker [MVP]

Hi,

Make the combobox owner drawn. Use measure string to figure out the
width needed to display the string and resize the combobox if necesssary.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim ds As New DataSet
Try
ds.ReadXml("http://forums.microsoft.com/MSDN/rss.aspx?ForumID=159&Mode=0&SiteID=1")

ComboBox1.DataSource = ds.Tables("item")
ComboBox1.DisplayMember = "title"
Dim g As Graphics = ComboBox1.CreateGraphics

For Each obj As Object In ComboBox1.Items
Dim drv As DataRowView
Dim s As String
Dim intWidth As Integer

drv = DirectCast(obj, DataRowView)
s = drv.Item("title").ToString
intWidth = g.MeasureString(s, ComboBox1.Font).Width
If ComboBox1.Width < intWidth Then ComboBox1.Width =
intWidth

Next

g.Dispose()
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub


Ken
 
V

VBTricks.de.vu Webmaster

Sorry,

this is not what I meant. I do not want to size the combobox depending
on it's content-length, but to use the available space of the toolbar
containing it, for its' width (like the address-combo in the IE).
But the source you wrote might be useful in another place...


Stefan


--
___________________________________www.VBTricks.de.vu
the free resource for Visual Basic, Gambas and Pascal
components, tips & complete projects

www: http://www.VBTricks.de.vu
mail: vbtricks <at> gmx <dot> net
_____________________________________________________
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top