Sign in to follow this  
NotSlyPee

C# DrawImage Error

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this