1

I have a simple Windows Form with a TabControl, but the AutoSize property doesn't seem to do anything. Here's what it looks like:

form

Here's my code:

$tabPage = [System.Windows.Forms.TabPage] @{
    AutoSize = $true
}
$tabControl = [System.Windows.Forms.TabControl] @{
    AutoSize = $true
}
$tabControl.Controls.Add($tabPage)
$form = [System.Windows.Forms.Form] @{
    AutoSize = $autoSize
    ClientSize = [System.Drawing.Size]::new(300, 300)
}
$form.Controls.Add($tabControl)

I would think the TabControl should fill the size of the form? I can of course set the Size or ClientSize properties, which works fine but I want it to be sized automatically vice setting a static size.

I found this question asking something very similar and the solution provided was to set the Anchor property, but I tried that and it didn't change anything:

$tabControl.Anchor = @([System.Windows.Forms.AnchorStyles]::Top, [System.Windows.Forms.AnchorStyles]::Left)

So what's the best way to accomplish this without setting a static size?

jerdub1993
  • 355
  • 1
  • 8
  • 3
    The documentation for TabControl says “This property is not relevant for this class.” which is probably why it doesn’t do anything - see https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.tabcontrol?view=windowsdesktop-7.0#properties. You probably want ```Dock = “Fill”``` instead - https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.dockstyle?view=windowsdesktop-7.0 – mclayton May 11 '23 at 06:33

0 Answers0