Reputation: 1055
I am creating a C# WinForm Application
(for a touch device "MS Surface Hub") using Visual Studio 2013
.
I have created two forms:
If a user interrupts by touching the screen on Form 1, the Introduction video stops playing and moves to Form 2. Here is my code to achieve this:
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();
}
However when I checked the Transition from Form 1 to Form 2, I observed a flicker effect
(i.e. I observed the back screen being displayed for a fraction of a second). How do I eliminate this effect?
I went through a lot of questions on Stack Forums and also read a lot of blogs, but didn't found a working solution. I was suggested to use a DoubleBuffered
property in my form, but it gave me the following Error:
Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement
Another suggestion was to use WS_EX_COMPOSITED 0x02000000L
, But I didn't found enough notes on how to accurately implement this in my code. A quote on this on 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.
I would like to know if there is a workaround for eliminating flicker effect.
Upvotes: 0
Views: 1689
Reputation: 1055
I achieved zero flickering by using sendToBack
and bringToFront
property of the form. I initially loaded both my forms in InitializeForm() function and then simply set these properties on my form on Touch event. By doing so the time to load a form i.e. using .show()
and .hide()
is eliminated.
Note: Both my forms are static
and thus I can apply these properties. In a scenario where which form is to be loaded is decided dynamically, I am not sure whether this will give the desired result. Any better solutions are welcomed.
Upvotes: 2