• Advertisement
Sign in to follow this  

C# DrawImage Error

This topic is 4000 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm new here and I'm quite new in C# programming. I've got a problem: i can't put an image without using labels and similar things because there could be 100 images or more and they are the same. That's why i don't want to use that much labels and besides the application would become complicated. I can't get image drawing to work while using System.Drawing.Image.DrawImage ("help" suggests me that). I can't call this void. How could i do that? Here's the code:
   public void DrawImagePoint(PaintEventArgs e)
{
// Create image.
Image newImage = Image.FromFile("o.JPG");
// Create Point for upper-left corner of image.
Point ulCorner = new Point( 100, 100);
// Draw image to screen.
e.Graphics.DrawImage(newImage, ulCorner);
}
[Edited by - NotSlyPee on March 11, 2007 9:35:20 AM]

Share this post


Link to post
Share on other sites
Advertisement
I'm not quite sure what you're trying to accomplish, but I'll try to answer your question. You should call the DrawImagePoint method from a method where you have access to the forms PaintEventArgs object. A good candidate would be your form's Paint event:


public void DrawImagePoint(PaintEventArgs e)
{
// Create image.
Image newImage = Image.FromFile("o.JPG");
// Create Point for upper-left corner of image.
Point ulCorner = new Point(100, 100);
// Draw image to screen.
e.Graphics.DrawImage(newImage, ulCorner);
}

private void Form1_Paint(object sender, PaintEventArgs e)
{
DrawImagePoint(e);
}


So if you want to display an image only in a certain case, you would want to put some kind of boolean check in the Form1_Paint event to only call the DrawImagePoint method when it's needed. There are other ways to accomplish the same end but hopefully this gives you a starting point.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement