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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

UserControl on TableLayoutPanel Sizing Issue

Status
Not open for further replies.

Borvik

Programmer
Jan 2, 2002
1,392
US
I have a UserControl that has a TableLayoutPanel on it. That panel has only one row and two columns - a NumericUpDown control in the first, and a ComboBox in the second.

Whenever the items in the combobox get updated the combobox is resized according to the following routine:
Code:
    Private Sub ResizeCombo()
        Dim g As Graphics = cboUnits.CreateGraphics
        Dim maxWidth As Integer
        For Each obj As Object In cboUnits.Items
            Dim s As String = obj.ToString
            Dim intWidth As Integer

            intWidth = CInt(g.MeasureString(s, cboUnits.Font).Width)
            maxWidth = Math.Max(maxWidth, intWidth)
        Next
        cboUnits.Width = maxWidth + SystemInformation.VerticalScrollBarWidth
        Me.Invalidate()
    End Sub
The column the ComboBox is in is also set to auto-size. The NumericUpDown column is set for a percentage and both controls have their anchor set to "Left, Right".

The above describe UserControl works fine - except when itself is placed within a TableLayoutPanel, at which point the size gets reduced to 0,0 and I am unable to resize it.

Any ideas on what is causing this or how to get around it?

Thanks.
 
Doggone it - the UserControl's AutoSize property was set to True - that was what was causing it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top