I'm writing a C# application and I want it to have a floating icon over the desktop (like the Facebook messenger in mobile).
I've been searching the internet but couldn't find anything useful. Any articles? Ideas?
I'm writing a C# application and I want it to have a floating icon over the desktop (like the Facebook messenger in mobile).
I've been searching the internet but couldn't find anything useful. Any articles? Ideas?
You need to create a form without title bar and border and use an image as background of your form. Also make area around the image, transparent. Then make the form movable.
FormBorderStyle to NoneTopMost to trueShowInTaskbar to false.BackgroundImage and set BackgroundImageLayout to CenterBackColor for form, for example if your BackGroundImage has Magenta color around, set the BackColor of form to Magenta.TransparencyKey of form to the color you choose for BackColorThis way you will have a shaped form, for example a circle form (if your background image was circle shape).
Then to make the form move by dragging with left mouse button, write this code:
public const int WM_NCLBUTTONDOWN = 0xA1;
public const int HT_CAPTION = 0x2;
[DllImportAttribute("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
[DllImportAttribute("user32.dll")]
public static extern bool ReleaseCapture();
protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);
if (e.Button == MouseButtons.Left)
{
ReleaseCapture();
SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
}
}
And don't forget to add using System.Runtime.InteropServices;
Here is the image used:
And as you see in the result below, now we have a floating icon above other windows:
To have a high quality Icon with more smooth edges take a look at this post: