Multiple images in a PictureBox Control

P

prynhart

I have a PictureBox Control which is 96*96 pixels. I want to display
nine 32*32 pixel bitmaps in this control arranged in a 3X3 square. How
can I do this ? All the examples I've seen load only one image in the
PictureBox.

The code:

board.ClientSize = new Size(96, 96);
board.Image = (Image)image1;

displays image1 in the top left hand corner. How can I display images
2 - 9 ?

Thanks,

Patrick
 
M

Michael Weber

I have a PictureBox Control which is 96*96 pixels. I want to display
nine 32*32 pixel bitmaps in this control arranged in a 3X3 square. How
can I do this ? All the examples I've seen load only one image in the
PictureBox.

The code:

board.ClientSize = new Size(96, 96);
board.Image = (Image)image1;

displays image1 in the top left hand corner. How can I display images
2 - 9 ?

Thanks,

Patrick


board..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(0, 32);
e.Graphics.DrawImage(image2, P2);

//.... and so forth

}


Best regards
Michael Weber
 
P

prynhart

Thank you Michael. This works!

Is it possible to load Bitmaps as a resource (rather than from disk).
At the moment, I have

private Bitmap image1, image2, ....;

public Form1()
{

InitializeComponent();
image1 = new Bitmap("C:\\C#\\image1.bmp");
image2 = new Bitmap("C:\\C#\\image2.bmp");
....
}

I notice that overload 8 of 12 for Bitmap is Bitmap.Bitmap(Type type,
string resource)

I've added the bmp's to solution explorer (right click, add existing
item), but I'm not sure what "type" should be. A few Google posts use
this.GetType()

I'm a C# Newbie but have a C++/MFC background.

Thanks again,

Regards, Patrick
 
A

atlaste

Well, type is the type of the resource class. So you add a resource
file, then add the bmp's to the resource file, the resource file has a
type. You can use that.

Usually I run into the slight problem that resource embedded files
lack an extension. So that would mean you get something like 'image1 =
new Bitmap(myResource.GetType(), "image1");

Hope that helps.

Cheers,

Stefan.
 

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