none
ListBox size Issues RRS feed

  • Question

  • To see what I mean, copy this into a blank form:

    Public Class Form1
        Dim LB As New ListBox With {.Location = New Point(10, 10), .Size = New Size(120, 400), _
                                    .Anchor = AnchorStyles.Top Or AnchorStyles.Bottom Or AnchorStyles.Left Or AnchorStyles.Right}
        Dim RTB As New RichTextBox With {.Location = New Point(140, 10), .Size = New Size(120, 400), _
                                         .Anchor = AnchorStyles.Top Or AnchorStyles.Bottom Or AnchorStyles.Left}
        Dim TB As New TextBox With {.Location = New Point(10, 410), .Size = New Size(120, 25), _
                                    .Anchor = AnchorStyles.Left Or AnchorStyles.Bottom}
    
        Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            Me.Size = New Size(300, 500)
            Me.Controls.Add(LB)
            Me.Controls.Add(RTB)
            Me.Controls.Add(TB)
            For i As Integer = 1 To 50
                LB.Items.Add(i.ToString("00000"))
            Next
        End Sub
    End Class
    

    As you make the form taller or shorter, the height of the ListBox gets smaller and smaller compared to the RichTextBox, then snaps back to nearly the same height. I assume that is because the ListBox "snaps" to a multiple of the ListBoxItem Height. Any ideas how to make it all appear nice ?

    If I set the RTB height equal to the LB height, they both move away from the textbox.
    Setting the LB height to the RTB height gets ignored unless it makes the LB height snap to the next available number.

    For what I am doing, a ListView looks fine but takes forever to add and display 4000+ Items

    Monday, June 12, 2017 7:29 PM

Answers

  • Devon,

    You can turn off the .IntegralHeight if you want but it will then show partial items.


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    • Proposed as answer by IronRazerz Monday, June 12, 2017 7:36 PM
    • Marked as answer by Devon_Nullman Monday, June 12, 2017 8:58 PM
    Monday, June 12, 2017 7:34 PM

All replies

  • Devon,

    You can turn off the .IntegralHeight if you want but it will then show partial items.


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    • Proposed as answer by IronRazerz Monday, June 12, 2017 7:36 PM
    • Marked as answer by Devon_Nullman Monday, June 12, 2017 8:58 PM
    Monday, June 12, 2017 7:34 PM
  • Devon,

    You can turn off the .IntegralHeight if you want but it will then show partial items.


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Thank You Frank.
    Monday, June 12, 2017 8:58 PM
  • Thank You Frank.
    I'm glad it helped. :)

    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Monday, June 12, 2017 8:59 PM