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

标签 c# winforms showdialog

有没有办法让窗体闪烁,就像失去焦点时的 ShowDialog?

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

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

最佳答案

试试这个。

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

根据您的需要扩展它。

关于c# - showdialog 重新聚焦效果自定义调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10938899/

相关文章:

c# - c# 中的字典或列表

c# - winforms 多表单布局

c++ - 如何更改在不同线程中打开的表单的标签文本?

wpf - 对话框窗口在其他窗口后面丢失

WPF ShowDialog 和 ElementHost

c# - wpf中的DialogResult问题

c# - 组合框自动完成不起作用

c# - 有没有办法获取对嵌入式资源文件的字符串路径引用?

c# - 在 c# 中延时后自行停止录音机(使用 NAudio)

c# - 为什么 Trackbar 值在向上箭头/PgUp 上减少?