Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# transparent border for borderless form

Tags:

c#

forms

winforms

I'm creating a borderless form and I want to add a custom border to it. When I add the background for the form however, it doesn't show well, and it is not transparent.

This is what I want to use as my border.: Screenshot

When I set the Form's transparency for White the shadow disappears, I'm not sure what to do.

like image 752
ptr0x01 Avatar asked May 03 '11 17:05

ptr0x01


2 Answers

There is a way to use a semi-transparent (alpha) image as the form background in WinForms, as described in this article: A lovely goldfish desktop pet (using alpha-PNG and GDI+).

It uses native interop to blend the image with the desktop.

Also, check out UpdateLayeredWindow function (User32.dll) on pinvoke.net. There is also an example how to use it.

[Edit]

There is also a link on pinvoke.net to Mike Swanson's blog article about the same subject. It uses the same code as described in mentioned links, but it's a VS project which does exactly what OP wants: a splash form with a semitransparent PNG image as a background.

like image 83
Groo Avatar answered Oct 16 '22 02:10

Groo


Okay so I cheated a bit but what I did was simply overriding the CreateParams to draw dropshadow even though it's a borderless window. It does exactly what I wanted so I went with it.
Thanks for all the help!

like image 39
ptr0x01 Avatar answered Oct 16 '22 02:10

ptr0x01