Selecting a PictureBox

F

Fao, Sean

I'm working on a Windows application (VS 2005) that I will need to be
able to select images I've added to a FlowLayoutPannel. I was
attempting to select the various PictureBoxes and noticed that it wasn't
working. Reading through the MSDN to find out why, I ran across the
following:

"The PictureBox is not a selectable control, which means that it cannot
receive input focus."

This obviously puts a damper on the project. Is there any workaround or
alternative image controls that can be selected?

Thank you in advance,
 
J

JustinC

It's somewhat of a hack, but could you place a transparent panel over
the PictureBox and wire it's focus received event to your underlying
picturebox?
 
B

Bruce Wood

I'm working on a Windows application (VS 2005) that I will need to be
able to select images I've added to a FlowLayoutPannel. I was
attempting to select the various PictureBoxes and noticed that it wasn't
working. Reading through the MSDN to find out why, I ran across the
following:

"The PictureBox is not a selectable control, which means that it cannot
receive input focus."

This obviously puts a damper on the project. Is there any workaround or
alternative image controls that can be selected?

In .NET 1.1 I wrote my own image gallery control that allows the user
to select images. Although the PictureBox can't be selected as such, it
can receive Click and DoubleClick events, and I just redraw the picture
with a colour wash to indicate that it is the currently selected
picture. In fact, I use two colours: one for "selected" and one for
"checked".

So... you can do it; you just have to "roll your own," as it were.
 
S

senfo

Ignacio said:
Can you use a ImageButton instead?

I'm actually doing this in a Windows application, which does not have an
ImageButton control like ASP.NET does (at least not that I know of).
You did, however, give me an idea. The Windows Button control *does*
have an Image property, which, for some reason, I never thought about
looking for.

At first glance, it appears that the Image property will provide the
functionality that I require.

Thank you very much for your help,
 
S

senfo

Bruce said:
In .NET 1.1 I wrote my own image gallery control that allows the user
to select images. Although the PictureBox can't be selected as such, it
can receive Click and DoubleClick events, and I just redraw the picture
with a colour wash to indicate that it is the currently selected
picture. In fact, I use two colours: one for "selected" and one for
"checked".

So... you can do it; you just have to "roll your own," as it were.

I was fighting this approach because I was convinced there must be
another way (I've often looked back on code I've written and realized
how much easier the problem actually was since I learned more). At any
rate, the Button just wasn't providing the functionality I was after, so
I ended up extending the PictureBox class to fit my intended design.

After all this fighting of the urge, you inspired me to give a try.
Turns out it took me no more than 30 minutes or so to get everything
done. I would have been further ahead if I had done this from the
beginning!

Thank you very much for the inspiration!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top