[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 352
  • Last Modified:

Picture on Picture in C# form

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.

1 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now