甲方爸爸提出了一个计数的需求,我软件运行在后台运行,他们要开一个实时监控的软件,但是还要我们软件出一个弹窗,要一直显示,记录他们扫码的次数;这个弹窗无论开什么软件都是在最上层,类似于搜狗输入法了,先贴效果,在贴代码:
using System.Runtime.InteropServices;
using System.Windows.Forms;
public partial class ShowFrom : Form
{
[DllImport("user32.dll", EntryPoint = "SetWindowPos")]
public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
public const uint SWP_NOMOVE = 0x2;
public const uint SWP_NOSIZE = 0x1;
public static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);
public static readonly IntPtr HWND_NOTOPMOST = new IntPtr(-2);
private void ShowFrom_Load_1(object sender, EventArgs e)
{
//将窗口置顶
SetWindowPos(this.Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
}
private void ShowFrom_FormClosing(object sender, FormClosingEventArgs e)
{
//在窗口关闭时,取消TopMost属性
this.TopMost = false;
}
}