What I have below is a dll that when ran and supplied with pos, pic, and transparency. Will display the picture on the screen, the picture will be the top most object no matter what. You will also be able to click through the picture. The problem I am having is, When using a circular picture it has white around the edges of the circle to make it square. I want to get rid of those white edges of the picture so i am just left with a circle that is top most and I can click through. Everything in the code below works except when I have f.TransparencyKey = BackColor; I can no longer click through the picture, but it does make it a circle. Now how would I make it so i can click through the picture while getting it to be a circle instead of a square?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace pic
{
public class Class1
{
[DllImport("user32.dll", SetLastError = true)]
private static extern UInt32 GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll")]
static extern int SetWindowLong(IntPtr hWnd, int nIndex, IntPtr dwNewLong);
[DllImport("user32.dll")]
static extern bool SetLayeredWindowAttributes(IntPtr hwnd, uint crKey, byte bAlpha, uint dwFlags);
public const int GWL_EXSTYLE = -20;
public const int WS_EX_LAYERED = 0x80000;
public const int WS_EX_TRANSPARENT = 0x20;
public const int LWA_ALPHA = 0x2;
public const int LWA_COLORKEY = 0x1;
public void t(int LocalX, int LocalY, string PicLocal, byte transparency)
{
Bitmap bitmap;
Form f = new Form();
f.BackColor = Color.White;
f.FormBorderStyle = FormBorderStyle.None;
f.Bounds = Screen.PrimaryScreen.Bounds;
f.TopMost = true;
bitmap = new Bitmap(PicLocal);
f.Size = new Size(bitmap.Size.Width, bitmap.Size.Height);
f.StartPosition = FormStartPosition.Manual;
f.SetDesktopLocation(LocalX, LocalY);
Application.EnableVisualStyles();
SetWindowLong(f.Handle, GWL_EXSTYLE,
(IntPtr)(GetWindowLong(f.Handle, GWL_EXSTYLE) | WS_EX_LAYERED | WS_EX_TRANSPARENT));
// set transparency to 50% (128)
SetLayeredWindowAttributes(f.Handle, 0, transparency, LWA_ALPHA);
f.BackgroundImage = Bitmap.FromFile(PicLocal);
//f.AllowTransparency = true;
//Color BackColor = Color.White;
// Make the background color of form display transparently.
//f.TransparencyKey = BackColor;
Application.Run(f);
}
}
}