Skip to content

Instantly share code, notes, and snippets.

@pinecones-sx
Last active June 6, 2019 03:05
Show Gist options
  • Save pinecones-sx/706b736d5a8f08902551ce2f0aa8100e to your computer and use it in GitHub Desktop.
Save pinecones-sx/706b736d5a8f08902551ce2f0aa8100e to your computer and use it in GitHub Desktop.
form is displaying offset control
<#
Panel should display centered in the form. Instead it display offset to the right and bottom.
#>
[void][Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')
[void][Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')
[void][Reflection.Assembly]::LoadWithPartialName('System.Drawing')
# Main form
$formToolbox = New-Object System.Windows.Forms.Form
$formToolbox.Size = [System.Drawing.Size]::new(400,500)
$formToolbox.StartPosition = 'CenterScreen'
#$formToolbox.FormBorderStyle = 'Fixed3D'
$formToolbox.SizeGripStyle = 'Hide'
$formToolbox.MaximizeBox = $false
$formToolbox.ShowInTaskbar = $true
$formToolbox.Text = 'I wont display right.'
$mainPanel = New-Object System.Windows.Forms.Panel
$mainPanel.Anchor = [System.Windows.Forms.AnchorStyles]::Top
$mainPanel.Size = [System.Drawing.Size]::new(($formToolbox.Width - 50),($formToolbox.Height - 50))
$mainPanel.Location = [System.Drawing.Point]::new(25,25)
$mainPanel.AutoScroll = $true
$mainPanel.BackColor = [System.Drawing.Color]::Black
$formToolbox.Controls.Add($mainPanel)
$formToolbox.BringToFront()
$formToolbox.ShowDialog()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment