Winforms Transparency Issue (i going crazy with it)

限于喜欢 提交于 2019-12-04 09:55:42
Ash

Johannes has mentioned the main issues with your current approach.

It is possible to do form alpha blending in Windows Forms but you will need to use the Windows API call (among others): UpdateLayeredWindow.

Visual C# kicks has a helpful tutorial and source code on how to do this to create a professional looking splash screen.

The only drawback is that if your form contains child controls such as buttons, textboxes, they will not be drawn using UpdateLayeredWindow. However you could still simulate buttons etc by manually drawing them as part of the form background.

Your problems here are

  • The PNG is anti-aliased
  • It is composited against the normal form background (SystemColors.Control)
  • If you make that transparent using the TransparencyKey property (which makes a single color transparent, but nothing else), you'll end up having opaqueness where the PNG had partial transparency

So far, so expected. Keep in mind: You're not drawing a partially-transparent PNG onto the screen; you're drawing it onto your form and you then take the end result and make a single color transparent. For all what it's worth, your PNG could have pink as the surrounding color, the result would be the same.

You may want to look at regions or don't anti-alias the PNG you're drawing.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!