tobixz
Goto Top

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:

$Uebersicht.Controls.Remove($pictureBox1)
zu löschen oder über:

$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

Content-ID: 4897618660

Url: https://administrator.de/contentid/4897618660

Ausgedruckt am: 21.11.2024 um 22:11 Uhr

141986
141986 09.12.2022 aktualisiert um 09:01:55 Uhr
Goto Top
Hi,


        $pictureBox1.Image.Dispose()
        Remove-Item $pictureBox1 -force
Ungetestet.
hth?

Grüße
4863114660
Lösung 4863114660 09.12.2022 aktualisiert um 10:02:57 Uhr
Goto Top
Ein
$picturebox1.Image = $null
reicht. Hier ne Beispiel Form schnell zusammen geklöppelt
#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