|
-
Aug 3rd, 2007, 07:54 PM
#1
Thread Starter
Addicted Member
[1.1] Add multiple images in a single picturebox
Hi all!
I have this load an image to a picturebox:
csharp Code:
private void onLoadImages(object sender, System.EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.InitialDirectory = System.Environment.CurrentDirectory;
ofd.Filter = "Icons (*.ico)|*.ico|BMPs (*.bmp)|*.bmp|GIFs (*.gif)|*.gif|JPEGs (*.jp*)|*.jp*|PNGs (*.png)|*.png";
if (ofd.ShowDialog(this) != DialogResult.Cancel)
{
Image img = Image.FromFile(ofd.FileName);
this.pictureBox1.Image = new Bitmap(img, new Size(32, 32));
}
}
But this, as you may know..replace the old image...I want to make like a imagelist viewer, so the the image will be next to another...any ideas?
-
Aug 3rd, 2007, 09:22 PM
#2
Re: [1.1] Add multiple images in a single picturebox
It's not possible to display more than one Image in a PictureBox. You can either use multiple PictureBoxes to display one Image each, or else combine all your individual images into a single Image object and display that in a single PictureBox. I'd be inclined to go with the first option.
-
Sep 20th, 2007, 02:04 PM
#3
New Member
Re: [1.1] Add multiple images in a single picturebox
Actually it IS possible to put more than one image in a picturebox. But only two ... backgroundimage and image if you use the properties.
So here's what you have to do to put MORE THAN ONE image in a picturebox control.
Code:
Bitmap BG1 = new Bitmap(BMP_FileName);
Bitmap BG2 = new Bitmap(BMP_FileName);
Bitmap BG3 = new Bitmap(BMP_FileName);
Bitmap BG4 = new Bitmap(BMP_FileName);
// overwrite paint
private void PictureBox_Paint(object sender, PaintEventArgs e)
{
// Create Point for upper-left corner of image1.
if (BG1 != null)
{
Point P1 = new Point(0, 0);
e.Graphics.DrawImage(BG1, P1);
}
if (BG2 != null)
{
Point P2 = new Point(0, 64);
e.Graphics.DrawImage(BG2, P2);
}
if (BG3 != null)
{
Point P3 = new Point(64, 0);
e.Graphics.DrawImage(BG3, P3);
}
if (BG4 != null)
{
Point P4 = new Point(64, 64);
e.Graphics.DrawImage(BG4, P4);
}
//.... and so forth
}
Last edited by bobphrapples1414; Sep 20th, 2007 at 02:43 PM.
Reason: found a solution
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|