We will add code to make the list box fill the app on form load and when the user resizes the app.
We need to make sure that scroll bars appear on the list box if the number of items is too many to fit.
Select the list box. In the properties window set ScrollAlwaysVisible to True, and HorizontalScrollBar to True.
Since we will change the size of the list box in two places we will use a general procedure:
Add the code shown below:
Private Sub resizeListBox()
'On form load and when the form is resized the list box fills the form
ListBox1.Width = Me.Width - 20 'leave room for the scroll bars on listbox
ListBox1.Height = Me.Height - ListBox1.Location.Y - 30 'below the menu
End Sub
Private Sub Form1_Resize(sender As Object, e As EventArgs) Handles Me.Resize
resizeListBox()
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
FontDialog1.Font = Me.Font 'Same font as the form
resizeListBox()
End Sub
See the
complete code at this point.