Question

I am writing a windows form program in Visual Studio 2013 using C#

The program is a memory game where the person can see which pictures are in which squares but as soon as they click the first picture, all of the pictures are hidden, so they have to try and remember which location each image was in.

I have a tablelayoutpanel with a grid of pictureBox's inside.

Some squares have a random image inside while others are just black squares

I want to make all non black images hidden(or appear hidden) when one image is clicked. I still want to have click events on the 'hidden' images.

I have tried pictureBox.visible = false; but obviously if the picture is not visible then it no longer accepts click events.

I have tried to set the pictureBox.ForeColor to Color.Gray but this either does not work or the fore color is behind the image. I tried the control.BringToFront() but I guess i was using the wrong control because I the color did not move in front of the image.

Is there a way to make an image appear hidden and still respond to mouse clicks, or is there a way to make a color appear over the image so that the image is still there but behind some Color.

Either way will be fine.

Was it helpful?

Solution

There is no way you can have something hidden/invisible and clickable.

One way to do this would be to replace the real image with a blank image. This could be the same colour as the background to make it look like the real image has disappeared.

Setting the ForeColor of the picture box would have no effect for an image.

Another way might be to set the opacity of the image to a very small positive value so that the image isn't completely transparent. This should still be clickable but it might still be visible if the user fiddles with the monitor brightness/contrast.

OTHER TIPS

@ChrisF's answer is correct.

What I want to say is that hidden is called what it is because it is hidden from the view, so that the user would not interact with it. The major point of hiding an element from the window is to preventing user from knowing that the element exists.

So the best solution would be adding a transparent image, or a blank one and make it clickable.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top