您需要创建一个没有标题栏和边框的表单,并使用图像作为表单的背景。还要使图像周围的区域透明。然后使表格可移动。
FormBorderStyle为NoneTopMost为trueShowInTaskbar为false。BackgroundImage设置BackgroundImageLayout为CenterBackColor的表单,例如,如果您周围BackGroundImage有Magenta颜色,则将BackColor表单的of设置为Magenta。TransparencyKey表单设置为您选择的颜色BackColor通过这种方式,您将拥有一个形状,例如圆形(如果您的背景图像是圆形)。
然后通过鼠标左键拖动使表单移动,编写以下代码:
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);
}
}
Run Code Online (Sandbox Code Playgroud)
并且不要忘记添加 using System.Runtime.InteropServices;
这是使用的图像:
正如您在下面的结果中看到的,现在我们在其他窗口上方有一个浮动图标:
要获得具有更平滑边缘的高质量图标,请查看这篇文章: