Bild in Powershell GUI löschen
Guten Abend, Ich möchte diese Bild löschen. Ich habe bereits die Variable als Global festzulegen und das Bild über:
zu löschen oder über:
Das Bild ist leider sehr hartnäckig und lässt sich nicht löschen, weiß jemand wieso? o.O
$Uebersicht.Controls.Remove($pictureBox1)
$pictureBox1.Dispose()
Das Bild ist leider sehr hartnäckig und lässt sich nicht löschen, weiß jemand wieso? o.O
$pictureBox1 = New-Object System.Windows.Forms.PictureBox
$pictureBox1.Size = New-Object System.Drawing.Size(300,200)
$pictureBox1.Location = New-Object System.Drawing.Point(300,50)
$Uebersicht.Controls.Add($pictureBox1)
$image1 = [System.Drawing.Image]::FromFile("C:\Users\Administrator\Desktop\images(2).png")
$pictureBox1.Image = $image1
Bitte markiere auch die Kommentare, die zur Lösung des Beitrags beigetragen haben
Content-ID: 4897618660
Url: https://administrator.de/forum/bild-in-powershell-gui-loeschen-4897618660.html
Ausgedruckt am: 22.12.2024 um 09:12 Uhr
2 Kommentare
Neuester Kommentar
Hi,
Ungetestet.
hth?
Grüße
$pictureBox1.Image.Dispose()
Remove-Item $pictureBox1 -force
hth?
Grüße
Ein
reicht. Hier ne Beispiel Form schnell zusammen geklöppelt
$picturebox1.Image = $null
#Generated Form Function
function GenerateForm {
#region Import the Assemblies
[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
#endregion
#region Generated Form Objects
$form1 = New-Object System.Windows.Forms.Form
$btnUnload = New-Object System.Windows.Forms.Button
$btnLoadImage = New-Object System.Windows.Forms.Button
$pictureBox1 = New-Object System.Windows.Forms.PictureBox
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
#endregion Generated Form Objects
#----------------------------------------------
# Event Script Blocks
#----------------------------------------------
#Provide Custom Code for events specified in PrimalForms.
$btnLoadImage_OnClick=
{
$dlg = New-Object System.Windows.Forms.OpenFileDialog -P @{Multiselect = $false}
if($dlg.ShowDialog() -eq 'OK'){
$pictureBox1.Image = [System.Drawing.Image]::FromFile($dlg.Filename)
}
}
$btnUnload_OnClick=
{
$picturebox1.Image = $null
}
$OnLoadForm_StateCorrection=
{#Correct the initial state of the form to prevent the .Net maximized form issue
$form1.WindowState = $InitialFormWindowState
}
#----------------------------------------------
#region Generated Form Code
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 272
$System_Drawing_Size.Width = 292
$form1.ClientSize = $System_Drawing_Size
$form1.DataBindings.DefaultDataSourceUpdateMode = 0
$form1.Name = "form1"
$form1.Text = "PictureBox"
$btnUnload.Anchor = 6
$btnUnload.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 93
$System_Drawing_Point.Y = 245
$btnUnload.Location = $System_Drawing_Point
$btnUnload.Name = "btnUnload"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 100
$btnUnload.Size = $System_Drawing_Size
$btnUnload.TabIndex = 2
$btnUnload.Text = "Unload Image"
$btnUnload.UseVisualStyleBackColor = $True
$btnUnload.add_Click($btnUnload_OnClick)
$form1.Controls.Add($btnUnload)
$btnLoadImage.Anchor = 6
$btnLoadImage.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 12
$System_Drawing_Point.Y = 245
$btnLoadImage.Location = $System_Drawing_Point
$btnLoadImage.Name = "btnLoadImage"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 75
$btnLoadImage.Size = $System_Drawing_Size
$btnLoadImage.TabIndex = 1
$btnLoadImage.Text = "Load Image"
$btnLoadImage.UseVisualStyleBackColor = $True
$btnLoadImage.add_Click($btnLoadImage_OnClick)
$form1.Controls.Add($btnLoadImage)
$pictureBox1.Anchor = 15
$pictureBox1.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 12
$System_Drawing_Point.Y = 12
$pictureBox1.Location = $System_Drawing_Point
$pictureBox1.Name = "pictureBox1"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 227
$System_Drawing_Size.Width = 268
$pictureBox1.Size = $System_Drawing_Size
$pictureBox1.SizeMode = 4
$pictureBox1.TabIndex = 0
$pictureBox1.TabStop = $False
$form1.Controls.Add($pictureBox1)
#endregion Generated Form Code
#Save the initial state of the form
$InitialFormWindowState = $form1.WindowState
#Init the OnLoad event to correct the initial state of the form
$form1.add_Load($OnLoadForm_StateCorrection)
#Show the Form
$form1.ShowDialog()| Out-Null
} #End Function
#Call the Function
GenerateForm