clearing a picturebox.

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 8 years and 3 weeks old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
Rodent
Posts: 40
Last visit: Tue Mar 01, 2022 3:39 pm

clearing a picturebox.

Post by Rodent »

Hi,

I am trying to clear all PictureBoxs by enumerating the controls in a GroupBox
e.g.

foreach ($control in $gbBasic.Controls)
{
If ($control.GetType().Name -eq "CheckBox") { $control.checked = $false }
If ($control.GetType().Name -eq "PictureBox") { $control.image = $il4.Images[0] }
}

The CheckBox controls are being unchecked but the PictureBoxes are not being cleared.

The image in the imagelist ($il4) [0] is a blank picture.
I have also tried:
$control.image = $null

Any help would be great.
Regards
Rodney
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: clearing a picturebox.

Post by jvierra »

Well Rodent (I bet you are related to Ratso Rizzo (https://en.wikipedia.org/wiki/Midnight_Cowboy).
What is meant by "clearing a picture box"? A PB is not a data carrier. It has no data value. It cannot be "cleared".

However ... you can do the following:

$picturebox1.Visible = $false
$picturebox1.Image=$null


Both methods will "clear" the box.
User avatar
Rodent
Posts: 40
Last visit: Tue Mar 01, 2022 3:39 pm

Re: clearing a picturebox.

Post by Rodent »

jvierra wrote:Well Rodent (I bet you are related to Ratso Rizzo (https://en.wikipedia.org/wiki/Midnight_Cowboy).
What is meant by "clearing a picture box"? A PB is not a data carrier. It has no data value. It cannot be "cleared".

However ... you can do the following:

$picturebox1.Visible = $false
$picturebox1.Image=$null


Both methods will "clear" the box.
Thanks jvierra...

Yes, I do know how to clear the image from a picture box, what I would like to know is why it does not work when you enumerate the controls?

I have about 20 picture boxes on my form so instead of listing each control by name that takes up 20 lines of code I can do the same job in a lot less lines.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: clearing a picturebox.

Post by jvierra »

There is no reason why that won't work. I suspect you have a bug in your code.
User avatar
Rodent
Posts: 40
Last visit: Tue Mar 01, 2022 3:39 pm

Re: clearing a picturebox.

Post by Rodent »

jvierra wrote:There is no reason why that won't work. I suspect you have a bug in your code.
Here is my code, it is very basic, hard to get wrong.

function reset_controls
{
foreach ($control in $gbBasic.Controls) # $gbBasic is a GroupBox with checkbox and picturebox controls in it.
{
If ($control.GetType().Name -eq "CheckBox") { $control.checked = $false }
If ($control.GetType().Name -eq "PictureBox") { $control.image = $null }
}
}

I would like some help in figuring out what is wrong with this code?
Regards
Rodney
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: clearing a picturebox.

Post by jvierra »

That is not all of your code. We need all of your PSF to understand what you are doing.
This topic is 8 years and 3 weeks old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked