C# panel onpaint event paint event args e.drawImage

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ahmedhussain
    New Member
    • Dec 2008
    • 79

    #1

    C# panel onpaint event paint event args e.drawImage

    Hi,

    I have a panel control in windows form. And I want an Image on the background of the panel. But I dont want to loop through it to draw images to it.

    Code:
    for (int i = 1; i <= 5; i++)
                {
                    int height = Resource1.owners_icon.Height * i;
                    int width = Resource1.owners_icon.Width;
                    for (int j = 1; j <= 5; j++)
                    {
                        e.Graphics.DrawImage(Resource1.owners_icon, j * width, height);
                    }
    My code actually draws an image multiple times. and I need it to do the same thing but I dont want loops.

    Do any one have the solution?
    Regards,
    Syed Ahmed Hussain
  • GaryTexmo
    Recognized Expert Top Contributor
    • Jul 2009
    • 1501

    #2
    I'm not sure I understand the question. Is it that you have a sequence of images and want to merge them all into one, then draw that as a single background image?

    If this is the case, why not just draw all the images to another image first (ie, whenever you read the images), then in the paint method just draw the merged image?

    If I've misunderstood, can you please clarify your question?

    Comment

    • Syed Hussain

      #3
      Hi Gary,
      I'm not sure I understand the question. Is it that you have a sequence of images and want to merge them all into one, then draw that as a single background image?
      I am actually having a single image of size 11 X 11 px name it abc.jpg. I want this Image to multiply on the background, i.e, when it prints on the background it wont be a single image it will be the set of this image.

      Let me put it this way. My code actually prints this image in a panel background multiple times, in a sequence, merged as a single image. Yes Gary you're thinking in the right direction.

      If this is the case, why not just draw all the images to another image first (ie, whenever you read the images), then in the paint method just draw the merged image?
      Can you please provide me a code snippet which actually you have tried or that you think might work?

      Thank you,

      Regards,

      Syed Ahmed Hussain

      Comment

      • GaryTexmo
        Recognized Expert Top Contributor
        • Jul 2009
        • 1501

        #4
        I'd be happy to help you get started :)

        The Graphics class provides a way to get a graphics handle to an image. Here's an example...

        Code:
        Image destImage = new Bitmap(500, 500);
        Graphics g = Graphics.FromImage(destImage);
        Now you can draw to that image... for example, another image.

        Code:
        g.DrawImage(srcImage, new Point(0, 0));
        In this way, you can do your tiling in, say, your constructor (or wherever you need to generate the image) using a loop but simply draw the final image.

        Comment

        Working...