|
Hey guys,
I've got a picture box that I'm using on a form that I'm creating. I set the background image to a picture of a human body diagram. I've been able to attach a GIF image as the main image for the picture box, and what it will do is allow me to overlay an "INJURY" over the body image in the background. This works great, but it only permits me to do 1 image at a time (in addition to the actual background image.
Is there any way to attach multiple images to a picture box?
Thanks!!!
Todd
| | Todd82TA Thursday, September 17, 2009 6:14 PM | Just implement its Paint event. Anything you draw there (with e.Graphics.DrawImage() for example) will be overlaid on top of the existing image. Or composite the image yourself by drawing in a Bitmap, then setting the Image property to that bitmap.
Hans Passant.- Marked As Answer byTodd82TA Thursday, September 17, 2009 8:07 PM
-
| | nobugz Thursday, September 17, 2009 8:03 PM | Thanks Hans, I appreciate it. I more or less came up with this based on what I was able to find, this goes along with what your answer suggested as well. (complete code)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication5
{
public partial class Form1 : Form
{
Image image1 = new Bitmap("C:\\image1.jpg");
Image image2 = new Bitmap("C:\\image2.jpg");
Image image3 = new Bitmap("C:\\image3.jpg");
Image image4 = new Bitmap("C:\\image4.jpg");
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
pictureBox1.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBox1_Paint);
}
private void pictureBox1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
// Create Point for upper-left corner of image1.
Point P1 = new Point(0, 0);
e.Graphics.DrawImage(image1 , P1);
Point P2 = new Point(32, 32);
e.Graphics.DrawImage(image2, P2);
Point P3 = new Point(64, 64);
e.Graphics.DrawImage(image3, P3);
Point P4 = new Point(96, 96);
e.Graphics.DrawImage(image4, P4);
}
}
}
- Marked As Answer byTodd82TA Thursday, September 17, 2009 8:08 PM
-
| | Todd82TA Thursday, September 17, 2009 8:07 PM | Just implement its Paint event. Anything you draw there (with e.Graphics.DrawImage() for example) will be overlaid on top of the existing image. Or composite the image yourself by drawing in a Bitmap, then setting the Image property to that bitmap.
Hans Passant.- Marked As Answer byTodd82TA Thursday, September 17, 2009 8:07 PM
-
| | nobugz Thursday, September 17, 2009 8:03 PM | Thanks Hans, I appreciate it. I more or less came up with this based on what I was able to find, this goes along with what your answer suggested as well. (complete code)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication5
{
public partial class Form1 : Form
{
Image image1 = new Bitmap("C:\\image1.jpg");
Image image2 = new Bitmap("C:\\image2.jpg");
Image image3 = new Bitmap("C:\\image3.jpg");
Image image4 = new Bitmap("C:\\image4.jpg");
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
pictureBox1.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBox1_Paint);
}
private void pictureBox1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
// Create Point for upper-left corner of image1.
Point P1 = new Point(0, 0);
e.Graphics.DrawImage(image1 , P1);
Point P2 = new Point(32, 32);
e.Graphics.DrawImage(image2, P2);
Point P3 = new Point(64, 64);
e.Graphics.DrawImage(image3, P3);
Point P4 = new Point(96, 96);
e.Graphics.DrawImage(image4, P4);
}
}
}
- Marked As Answer byTodd82TA Thursday, September 17, 2009 8:08 PM
-
| | Todd82TA Thursday, September 17, 2009 8:07 PM |
|