Click here to Skip to main content
15,917,618 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi people... i am currently building an application to manipulate images on a windows form.The problem i am facing is that i want the pictures that are loaded onto the panels (there are 2 panels) to be selectable so that the user can select individual pictures and merge,split or delete them. i am using c# .

Thanks in advance
:confused:
Posted
Comments
OriginalGriff 24-Aug-10 5:16am    
"is there no other way to select image within the panel ie. mouse events or can.select ?"
See modified answer
OriginalGriff 24-Aug-10 5:24am    
Well - it's modified now, anyway: the phone rang...

1 solution

A Panel doesn't have a Image property - you will either have to:
1) Put a PictureBox in each panel (and dock it to fill the whole thing) then work with the PictureBox.Image property,
or
2) Draw the image yourself in the Panel.Paint event.

Which you use will depend on what you need - if your images are always those a PictureBox knows, then that may be enough. If you want to do anything with the image in the panel (such as captions, colour changes, lines, boxes, etc), then draw it yourself.

[edit] V2.0
Neither the Paint event nor a PictureBox will select an image for you - you will have to add your own browse code for either. For a quick-and-nasty-but-give-you-the-idea solution, shove in a picture box or two and add a handler for the Click event which routes then both to the same routine.
In this handler, the "sender" parameter tells you which PictureBox was clicked, and you can use the FileDialog class to select a file.
private void pictureBox_Click(object sender, EventArgs e)
    {
    PictureBox pic = sender as PictureBox;
    if (pic != null)
        {
        OpenFileDialog ofd = new OpenFileDialog();
        if (ofd.ShowDialog() == DialogResult.OK)
            {
            pic.Image = Image.FromFile(ofd.FileName);
            }
        }
    }
This code is way from complete - your will want to set filters, etc., etc., but it give you a starting point

[/edit]
 
Share this answer
 
v2
Comments
Rico_ 24-Aug-10 5:10am    
hi OriginalGriff ...thanks for the solution. i have tried the Panel.Paint event and it has given me more grief than anything. Will try to sort out the problem with PictureBox , is there no other way to select image within the panel ie. mouse events or can.select ?
Rico_ 24-Aug-10 7:09am    
worked 100% , thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900