Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

PowerShell/Windows Forms – How to add ScrollAble control to a tab?

I’m creating a form with WinForms and I want to add a scrollable area with multiple Labels and TextBoxes.

Here’s my code for the form (there’s more to it that’s specific to my project, but this should be the gist of it):

$form                              = New-Object system.Windows.Forms.Form
$form.ClientSize                   = New-Object System.Drawing.Point(350,380)

$tabcontrol                        = New-object System.Windows.Forms.TabControl 
$tabcontrol.Size                   = New-Object System.Drawing.Point(330,330)
$tabcontrol.Location               = New-Object System.Drawing.Point(10,10)
$form.Controls.Add($tabcontrol)

$tab                               = New-object System.Windows.Forms.Tabpage
$tab.Text                          = "Tab1"
$tabcontrol.Controls.Add($tab)

I’ve tried adding a ScrollableControl to $tab:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

$scroll                            = New-Object System.Windows.Forms.ScrollableControl
$scroll.AutoScroll                 = $true
$scroll.AutoScrollMinSize          = New-Object System.Drawing.Size (0, 200)
$scroll.VerticalScroll.LargeChange = 20
$scroll.VerticalScroll.SmallChange = 7
$tab.Controls.Add($scroll)

When I launch the form, there’s no scroll bar or anything on Tab1 ($tab). I’ve tried adding controls to $scroll, like a System.Windows.Forms.Label or System.Windows.Forms.TextBox, but still nothing.

So what am I doing wrong? How would I add a scrollable control to $tab?

>Solution :

Instead of adding a ScrollableControl, you need to make sure the tab page is scrollable. Add this (with $tab being the Tab page):

$tab.AutoScroll = true
$tab.Size = New-Object System.Drawing.Size (1000, 1000)

This will automatically provide a scrollbar when the Window is smaller than the content of the page.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading