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
clearing a picturebox.
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.
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.
Re: clearing a picturebox.
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.
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.
Re: clearing a picturebox.
Thanks jvierra...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.
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.
Re: clearing a picturebox.
Here is my code, it is very basic, hard to get wrong.jvierra wrote:There is no reason why that won't work. I suspect you have a bug in your code.
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