Picture on Picture in C# form

Posted on 2009-04-20
Last Modified: 2013-12-17
In my application, I have a form with Picture element which displays a  jpg image. The requirement is, on the top of the jpg image, there should be a "png". Some portion of the "png" is transparent and so at those places, you can see the jpg image which is beneath the "png".

Is this type of functionality possible in C# Forms (picture over picture).  I have tried to create a new picture element for the "png", but it defeated the purpose of transparency, since the picture box itself is opaque, I have set the background color of the top level picture box as "Transparent" but still I don't see any transparency.

Is there any solution for this.

Question by:ukalyan
    1 Comment
    LVL 16

    Accepted Solution

    Yeah this is possible. I tried it and it works.

    Here is what I did:

    1. In my form, I added a PictureBox (which will contain the backgrond jpg Image).
    2. I set the BackGroundImage property of the picture box to the required image file. (say BackImg.jpg)
    3. Now add a handler to the Paint event of the picture box
    4. Add the following code to the handler

    private void pictureBox1_Paint(object sender, PaintEventArgs e)
            Image frontImg = Image.FromFile(@"D:\Images\FrontImg.png");
            // The required parameters for DrawImage are image, x, y, width, height
            e.Graphics.DrawImage(frontImg, 100, 100, 150, 150);
    // The above code will draw the transparent PNG on top of your existing JPG.

    Open in new window


    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
    More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    730 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now