Hello,
i need to have semi-transparent image (by using alpha blending) drawn on fully transparent form - it means that image will be drawn over form transparent content.
Currently image is always drawn over window background color even if window itself is transparent.
This is current state, thanks for any help.
public Form1()
{
InitializeComponent();
SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true);
MakeTransparent();
}
private void MakeTransparent()
{
NativeMethods.SetLayeredWindowAttributes(Handle, COLORREF.FromColor(BackColor), 255, Constants.ULW_ALPHA | Constants.ULW_COLORKEY);
}
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.Style |= (Constants.WS_EX_LAYERED | Constants.WS_EX_TOOLWINDOW);
return cp;
}
}
private void OnPaint(object sender, PaintEventArgs e)
{
using (Bitmap bitmap = new Bitmap("c:\\semi-transparent.png"))
{
e.Graphics.DrawImage(bitmap, 0, 0);
}
}