1

I'm having this problem. I would like for the frog's background to be transparent so the log underneath can be seen, but instead, the background picturebox's color is shown.

problem

I googled the problem and got the suggestion to change the Parent of the picturebox, which i tried, but this happened:

it works, but only in the log's picturebox area

I'm clearly doing something wrong. Can somebody help?

  • It will work fine if you strictly take care to use only control __nesting__, not __overlapping__. This must be done in code for pictureboxes. However the moments when the frog is half on and half off a log is a problem. You may want to have a look at [this](http://stackoverflow.com/questions/35107257/how-to-add-label-transparency-in-picturebox-c/35107623?s=6|0.0865#35107623) solution, which uses __two__ instances of a control (a Label) to achieve it. But drawing the frog all along on top of the large map is clearly a nice option as well.. – TaW Mar 25 '16 at 01:19
  • It's better to make your game objects independent from controls and use GDI+ to draw them on a drawing surface, but if you want to continue using controls as your game objects, you may find this post helpful: [How to make two transparent layer with c#?](http://stackoverflow.com/a/36102074/3110834) – Reza Aghaei Mar 25 '16 at 02:09

1 Answers1

0

WinForms does not support true alpha-transparency. "Transparent" controls re-render only the parent form's background behind themselves - controls cannot be truely layered and blended in the Z-axis.

So what you're after really isn't possible.

However, implementing a game using WinForms controls and GDI (System.Drawing) is a bad idea - performance is terrible (in part due to Microsoft's crippling of GDI since Windows Vista by removing hardware acceleration of many operations) and there are endless issues with inconsistent double-buffering and DPI-scaling.

I suggest you rewrite your game's rendering layer in Unity, Direct2D or SDL.

Dai
  • 141,631
  • 28
  • 261
  • 374
  • This is for a school assignment, so i have to use WinForms. Thanks anyway – Zugoldragon Mar 24 '16 at 23:40
  • @Zugoldragon Then I suggest implementing your own single `Control` subclass and draw the game manually using GDI without using any overlapping controls. That will work and allow you to use transparency. – Dai Mar 25 '16 at 00:00
  • like this one? http://stackoverflow.com/questions/395256/transparent-images-with-c-sharp-winforms/434706#434706 – Zugoldragon Mar 25 '16 at 00:06