消除 C# WinForms 应用程序中的闪烁

Eliminate Flickering in C# WinForms Application

我正在使用 Visual Studio 2013 创建一个 C# WinForm Application(用于触摸设备 "MS Surface Hub")。
我创建了两种形式:

  1. 第一个表单包含在表单加载时运行的介绍视频 (axWindowsMediaPlayer)
  2. 第二种形式包含菜单(Flash 文件)

如果用户通过触摸 Form 1 的屏幕中断,介绍视频将停止播放并移至 Form 2。这是我实现此目的的代码:

private void axWindowsMediaPlayer_ClickEvent(object sender, AxWMPLib._WMPOCXEvents_ClickEvent e)
    {
        Player.close();
        var menu = new Menu();
        menu.Closed += (s, args) => this.Close();
        menu.Show();
        this.Hide();
    }

然而,当我检查从 Form 1 到 Form 2 的过渡时,我观察到 flicker effect(即我观察到后屏幕显示了一小部分秒)。我该如何消除这种影响?

我在 Stack 论坛上经历了很多问题,也阅读了很多博客,但没有找到有效的解决方案。有人建议我在我的表单中使用 DoubleBuffered 属性,但它给了我以下错误:

Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement

另一个建议是使用 WS_EX_COMPOSITED 0x02000000L,但我没有找到足够的注释来说明如何在我的代码中准确地实现它。 MSDN 上对此的引用:

Paints all descendants of a window in bottom-to-top painting order using double-buffering. For more information, see Remarks. This cannot be used if the window has a class style of either CS_OWNDC or CS_CLASSDC.

我想知道是否有消除闪烁效果的解决方法。

我通过使用表格的sendToBackbringToFront属性实现了零闪烁。我最初在 InitializeForm() 函数中加载了我的两个表单,然后在 Touch 事件中简单地在我的表单上设置了这些属性。通过这样做,加载表单的时间即使用 .show().hide() 被消除。

注意: 我的两个表单都是 static 因此我可以应用这些属性。在动态决定要加载哪个表单的情况下,我不确定这是否会给出所需的结果。欢迎任何更好的解决方案。