2

有没有办法让表单闪烁,比如失去焦点时的 ShowDialog?

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

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

4

1 回答 1

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

根据您的需要扩展它。

于 2012-06-07T21:02:04.807 回答