showdialog重新聚焦效果自定义调用

时间:2012-06-07 19:53:56

标签: c# winforms showdialog

有没有办法让表单闪烁,就像ShowDialog失去焦点一样?

当您在Windows窗体上调用ShowDialog并尝试其他操作时,窗体会闪烁几秒钟,然后进行对焦。

有没有办法以自定义方式调用闪烁动作?

1 个答案:

答案 0 :(得分:3)

试试这个。

    [DllImport("user32.dll")]
    private static extern Int32 FlashWindowEx(ref FLASHWINFO pwfi);

    [StructLayout(LayoutKind.Sequential)]
    private struct FLASHWINFO {
        public UInt32 cbSize;
        public IntPtr hwnd;
        public FLASHW dwFlags;
        public UInt32 uCount;
        public Int32 dwTimeout;
    }

    [Flags]
    private enum FLASHW: int {
        // stop flashing
        FLASHW_STOP = 0x00,
        // flash the window title
        FLASHW_CAPTION = 0x01,
        // flash the taskbar button
        FLASHW_TRAY = 0x02,
        // flash the window title and the taskbar button
        FLASHW_ALL = 0x03,
        // flash continuously
        FLASHW_TIMER = 0x04,
        // flash until the window comes to the foreground
        FLASHW_TIMERNOFG = 0x0c,
    }

    public static void FlashWindow(IWin32Window form, int count) {
        FLASHWINFO pwfi = new FLASHWINFO();
        pwfi.cbSize = (uint)Marshal.SizeOf(pwfi);
        pwfi.dwFlags = FLASHW.FLASHW_ALL;
        pwfi.dwTimeout = 0;
        pwfi.hwnd = form.Handle;
        pwfi.uCount = (uint)count;
        FlashWindowEx(ref pwfi);
    }

根据您的需要进行扩展。