I am using a UserControl as a sidebar for my MainScreen form. The form height is 460px and I have created the UserControl as 460px but the scroll bar is on the MainScreen is showing the whole height of all the static buttons of the side bar which is around 719 pixels. I have resized the UserControl to show the scroll bar as 460px height but when I add it to the MainScreen form, after debugging it is showing as 719px height. There is no where in the code that is setting that amount and I have tried adding the follow code in the MainScreen to no avial.
<code>Private Sub MainScreen_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' Set the height of Sidebar2
' Add the VScrollBar control to the form
Controls.Add(VScrollBar1)
' Set the properties of the VScrollBar control
VScrollBar1.Dock = DockStyle.Right
VScrollBar1.Height = Sidebar2.Height ' Set the height of the scrollbar to match Sidebar2
VScrollBar1.Maximum = 440 ' Adjust the maximum value as needed
VScrollBar1.SmallChange = 20
' Set the form's border style to FixedSingle to disallow resizing
Me.FormBorderStyle = FormBorderStyle.FixedSingle
' Center the Label and PictureBox in Sidebar2
Label1.Location = New Point((Sidebar2.Width - Label1.Width) 2, (Sidebar2.Height - Label1.Height - PictureBox1.Height - 10) 2)
PictureBox1.Location = New Point((Sidebar2.Width - PictureBox1.Width) 2, Label1.Bottom + 10)
' Turn off horizontal scrollbar for Sidebar2
Sidebar2.HorizontalScroll.Enabled = False
<code>Private Sub MainScreen_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' Set the height of Sidebar2
Sidebar2.Height = 440
' Add the VScrollBar control to the form
Controls.Add(VScrollBar1)
' Set the properties of the VScrollBar control
VScrollBar1.Dock = DockStyle.Right
VScrollBar1.Height = Sidebar2.Height ' Set the height of the scrollbar to match Sidebar2
VScrollBar1.Minimum = 0
VScrollBar1.Maximum = 440 ' Adjust the maximum value as needed
VScrollBar1.SmallChange = 20
VScrollBar1.Value = 0
' Set the form's border style to FixedSingle to disallow resizing
Me.FormBorderStyle = FormBorderStyle.FixedSingle
' Center the Label and PictureBox in Sidebar2
Label1.Location = New Point((Sidebar2.Width - Label1.Width) 2, (Sidebar2.Height - Label1.Height - PictureBox1.Height - 10) 2)
PictureBox1.Location = New Point((Sidebar2.Width - PictureBox1.Width) 2, Label1.Bottom + 10)
' Turn off horizontal scrollbar for Sidebar2
Sidebar2.HorizontalScroll.Enabled = False
</code>
Private Sub MainScreen_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' Set the height of Sidebar2
Sidebar2.Height = 440
' Add the VScrollBar control to the form
Controls.Add(VScrollBar1)
' Set the properties of the VScrollBar control
VScrollBar1.Dock = DockStyle.Right
VScrollBar1.Height = Sidebar2.Height ' Set the height of the scrollbar to match Sidebar2
VScrollBar1.Minimum = 0
VScrollBar1.Maximum = 440 ' Adjust the maximum value as needed
VScrollBar1.SmallChange = 20
VScrollBar1.Value = 0
' Set the form's border style to FixedSingle to disallow resizing
Me.FormBorderStyle = FormBorderStyle.FixedSingle
' Center the Label and PictureBox in Sidebar2
Label1.Location = New Point((Sidebar2.Width - Label1.Width) 2, (Sidebar2.Height - Label1.Height - PictureBox1.Height - 10) 2)
PictureBox1.Location = New Point((Sidebar2.Width - PictureBox1.Width) 2, Label1.Bottom + 10)
' Turn off horizontal scrollbar for Sidebar2
Sidebar2.HorizontalScroll.Enabled = False
End Sub
Any help is greatly appreciated.