473,320 Members | 1,859 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Multiple images in a PictureBox Control

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

Apr 19 '07 #1
3 12312

<pr******@gmail.comskrev i en meddelelse
news:11**********************@n59g2000hsh.googlegr oups.com...
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.pictur eBox1_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
Apr 20 '07 #2
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

Apr 20 '07 #3
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.

On 20 apr, 03:46, prynh...@gmail.com wrote:
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

Apr 20 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Frank C. | last post by:
Hi all. I'm writing in this newsgroup for the first time. Can you hel me? I'm developing a program that plays an AVI file in a picturebox. (using MCI control with output to picturebox) I...
2
by: Kanaiya | last post by:
hello i want to put bitmap file which is midium size (on disk it is full size) in to some control which display it like thumbnail type any idea about it. -- With regards, Gangani Kanaiya.
11
by: Andy Chan | last post by:
First of all, thanks to Crirus and Fergus for helping me with a related posted a few days ago. Ok, I can add images to my form (for whatever reason I cannot added more than 1 image within the...
18
by: Andrew Christiansen | last post by:
Hey all. The images I create in photoshop with semi-transparent pixels (for instance in Photoshop text with a dropshadow with a transparent canvas) I've been saving in PNG format and then using...
0
by: Marcus Kwok | last post by:
I have written a class (Windows Form) in Managed C++ that accepts an array of image filenames and will display them sequentially. All images will be the same size. I got it to work, but I know...
0
by: Rob | last post by:
I've created an application which is intended to allow users to draw a diagram of a network - with workstations, servers, switches, links (all devices in my language) etc. I've created a user...
4
by: =?Utf-8?B?U3BlZWR5?= | last post by:
Hi there, I am currently writing an application where one inspects images and annotates certain features. Thus, one has to zoom in (4x) and pan around. The features are marked with little red...
1
by: Amnu | last post by:
Hi there, I've been told to write a custom control using C#.NET ( 2.0 ). This control should be able to display images and give access to zoom functionality. I've visited numerous How-To pages...
11
by: Usenet User | last post by:
..NET 1.1/2.0 I have a need to display high-resolution scrollable images in a .NET application (Windows Forms). One well known solution is to create a Panel with AutoScroll set to "true" and...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.