C# 创建一个类似于搜狗输入法,一直在页面最上层的弹窗

       甲方爸爸提出了一个计数的需求,我软件运行在后台运行,他们要开一个实时监控的软件,但是还要我们软件出一个弹窗,要一直显示,记录他们扫码的次数;这个弹窗无论开什么软件都是在最上层,类似于搜狗输入法了,先贴效果,在贴代码:

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;
        }

}

  • 10
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值