Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Friday, July 25, 2014 8:14 PM
I'm having a problem showing scroll bars on my form. I have a TabControl docked in my form and I set the MinimumSize property. I would expect the scroll bars to be shown when the forms Load event is done executing. Why am I not seeing them?
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.SuspendLayout()
Dim tabControl As New TabControl
With tabControl
For i = 1 To 3
.TabPages.Add(String.Format("TabPage{0}", i))
Next i
.MinimumSize = New Size(400, 400)
.Dock = DockStyle.Fill
End With
Me.Controls.Add(tabControl)
Me.ResumeLayout()
Me.AutoScroll = True
Me.Size = New Size(300, 300)
End Sub
End Class
Ryan
All replies (3)
Saturday, July 26, 2014 11:37 PM âś…Answered | 1 vote
Hi,
About the only way i can imagine doing this is to set the TabPages AutoScroll properties to true as you add them to the TabControl instead of trying to use the Forms AutoScroll.
Private Sub Form2_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
Dim tabControl As New TabControl
With tabControl
For i = 1 To 3
Dim tp As New TabPage(String.Format("TabPage{0}", i))
tp.AutoScroll = True 'set the tabpages AutoScroll to true
.TabPages.Add(tp)
Next i
.Dock = DockStyle.Fill
End With
Me.Controls.Add(tabControl)
Dim userControl As New UserControl
userControl.BackColor = Color.Aqua
tabControl.TabPages(0).Controls.Add(userControl)
userControl.Location = New Point(200, 200)
Me.Size = New Size(300, 300)
End Sub
If you say it can`t be done then i`ll try it
Friday, July 25, 2014 9:18 PM
Hi,
Its because the .Dock = DockStyle.Fill line. It tells the Tab control to fill the client area of the form. Meaning, it will adjust its size to the size of the client area of the form no mater what size you make the form. Try commenting out that line and the scroll bars will show. You will want to set the size of the TabControl larger than the ClientSize of the form. 8)
If you say it can`t be done then i`ll try it
Saturday, July 26, 2014 10:46 PM
Thanks for the reply IronRazerz.
I guess I didn't give the complete question, sorry. How do I get the form to get the scroll bars to automatically show if any of the child controls in the TabControl become unviewable if the parent form is resized? For example, I altered my original code to add a usercontrol to the bottom-right of the form and resized the form to partially hide the usercontrol, but the scroll bars don't appear, why?
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.SuspendLayout()
Dim tabControl As New TabControl
With tabControl
For i = 1 To 3
.TabPages.Add(String.Format("TabPage{0}", i))
Next i
.Dock = DockStyle.Fill
End With
Me.Controls.Add(tabControl)
Dim userControl As New UserControl
userControl.BackColor = Color.Aqua
tabControl.TabPages(0).Controls.Add(userControl)
userControl.Location = New Point(200, 200)
Me.ResumeLayout()
Me.AutoScroll = True
Me.Size = New Size(300, 300)
End Sub
Ryan