C WinForm Control Solution to Opaque Pictures When Transparent Pictures Overlap

  • 2021-10-13 08:27:40
  • OfStack

This article describes the simple solution to the opaque picture when the C # WinForm control overlaps the transparent picture. Share it for your reference, as follows:

In Winform, if you put a transparent picture on the form, it can show transparency normally, but if you put the picture on another control, it will not show transparency.

To solve this situation, you can use GDI + to draw a transparent picture on the control.

Here, let's take an pictureBox2 control overlapping an png transparent picture as an example:

We only need to add Paint event to pictureBox2 control, and then draw png transparent picture. The code is as follows:


private void pictureBox2_Paint(object sender, PaintEventArgs e)
{
  Graphics g = e.Graphics;
  Image image = Image.FromFile(@"e:\cclock.png");
  g.DrawImage(image, new Point(20, 10));
}

For more readers interested in C # related content, please check out the topics on this site: "C # Common Control Usage Tutorial", "WinForm Control Usage Summary", "C # Data Structure and Algorithm Tutorial", "C # Object-Oriented Programming Introduction Tutorial" and "C # Programming Thread Use Skills Summary"

I hope this article is helpful to everyone's C # programming.


Related articles: