If this is a dumb question, forgive me. I have a small amount of experience with C#, but not to this degree yet.
I have a series of images that I want to put into a grid with space around each image, also text beneath them and I want them to be clickable, so when they’re clicked they hilite, and double click runs an event. The best example I have for this is the user interface of the program ACDSee. I’ve googled this for hours, and haven’t come up with anything applicable. Is this difficult or simple? Can anyone give me an example, or point me in the right direction?
Cheers.
It doesn’t seem to be very difficult. I would suggest the following steps:
PictureBoxand aLabelorLinkLabelat its bottom.Paddingproperty of the user control.FlowLayoutPanel, and simply add instances of the above mentioned user-control to this panel.IsSelectedproperty for the user-control as well.Clickevent of the user-control and assign the events for all thumbnail instances to a single event-handler method. Store a global reference to the already selected thumbnail, name it e.g.,SelectedThumbnailinitialized with null. In the event-handler body compare thesenderwith the globalSelectedThumbnail, and update it if required. If the user-control associated with thesenderis not selected (i.e., its background is not blue, orIsSelectedisfalse) make it selected, or change its background. Otherwise change the background to its default color (e.g., control-face).The
Clickevent handler body looks something like this:It’s also recommended that all thumbnail instances that are going to be added to the so-called grid, be referenced in a separate array too. Therefore changing selection with arrow-keys would be possible with simple index calculations.
Further Notes: I assumed that the user-control that is to be created is named
MyThumbnailControl, just a random name to refer to that control. When you create a new user-control, the wizard generates a class for you with your desired name (e.g.,MyThumbnailControl), you can define a property inside it namedIsSelectedand implement its getter and setter. See this for a tutorial. After defining the user-control you can instantiate instances from its corresponding class. Also by global reference, I meant a variable at the form (or any parent control) level. To keep it simple we can add a reference of the selected thumbnail in the form that is going to hold the grid and thumbnails:MyThumbnailControl selectedThumb = null;or something like this in the body of the form.