jerom987
jerom987

Reputation: 1205

Windows Forms in powershell, display picturebox on bottom of page

I am making a windows form using powershell code.

I make the form, fill it with a couple of pictureboxes using a loop and then at the end I want to display a logo on the bottom of the page below all pictureboxes.

Form is created with these properties:

$form = new-object Windows.Forms.Form
$form.Text = "Title"
$form.AutoSize=$true
$form.AutoSizeMode= "GrowAndShrink"

I add the pictureboxes which I need and then I use this code to create the logo.

$Picture = (get-item ("URL TO IMAGE FILE"))
$img = [System.Drawing.Image]::Fromfile($Picture)
$pictureBox = new-object Windows.Forms.PictureBox
$pictureBox.Width =  $img.Size.Width
$pictureBox.Height =  $img.Size.Height
$pictureBox.Image = $img
$pictureBox.Anchor = [System.Windows.Forms.AnchorStyles]::Bottom
$form.controls.add($pictureBox)

The issue is that the logo is displayed, floating on the top of the page. I use this code to display the form.

$form.Add_Shown( { $form.Activate() } )
$form.ShowDialog()

I don't know if the issue is that I need to "update" the form after showing it the first time or if there's something wrong with the anchor. I tried docking it too, but then it shows on the bottom of the page but behind the other pictureboxes.

Upvotes: 2

Views: 7983

Answers (1)

cet51
cet51

Reputation: 1226

$pictureBox.Location = New-object System.Drawing.Size(x,y)

Play around with the X and Y coordinates in order to get the picturebox in the right place on your form.

EDIT/ADD:

I should add that you can set those coordinates according to the sides (left, right, top, bottom) of other objects you have on your form, something like this:

$pictureBox.Location = New-object System.Drawing.Size($formobj.bottom+10,$formobj.right+10)

Upvotes: 2

Related Questions