Fade Transition Trick

G

Guest

We are trying to use basic windows forms to do "fancy" transitions on our
application. When switching between main form controls (docked to full), we
want to make it look like one is fading out and the other fading in. Since
the UserControls don't support 'Opacity' I built a transition panel that
shows a modal form (with internal timer) that fades out, then back in when
the next control is shown. The Transition form is shown over the area of the
main form's child controls.

It functions as expected, however when the transition form hits opacity 1.0
(goes from 0 to 1, to 0 again to simulate fading out then back in), I get a
flash of black once before it starts to fade back to 0 opacity.

The backcolor and forecolor are set to white. I have overriden
OnPaintBackground, but it isn't being called. It definitely seems like the
parent is refreshing (because I change the control states of the main control
to visible at the mid fade point) and causing the modal dialog to repaint
black.

If it flashed white, I would be OK with that, but I would prefer it to
always repaint the current screen. In MFC and C++ I recall that you could
setup the default brush for erasing. Not sure if there is a .NET equivalent.

I do have a picture box on the form. Is it possible that it's
OnPaingBackground is causing the flash?

Any thougths would be helpful. I am sure I am missing some vital step here.
 
B

Bob Powell [MVP]

For almost any reasonably intellient paint scheme one should disable the
OnPaintBackground.

--
--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
G

Guest

So how do I disable the OnPaintBackground? I tried overriding
OnPaintBackground but it never gets called. I tried setting window styles to
UserPaint and AllPaintingInWMPaint, but that didn't make either OnPaint or
OnPaintBackground get called.

Could this be related to layered windows? I read something about the .NET
transition to a layered window has an error that causes flicker. The
workaround was to set a transparent key color, which forces .NET to layer the
window. This solved the flicker problem, BUT it made the window insanely
slow to transition, esepcially when maximized.

--
Brian R.



Bob Powell said:
For almost any reasonably intellient paint scheme one should disable the
OnPaintBackground.

--
--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
L

Linda Liu [MSFT]

Hi Brian,

It would be better for me to look into this issue if you could send me a
simple project that could just reproduce the problem.

To get my actual email address, remove 'online' from my displayed email
address.

Thank you for your understanding and cooperation!

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
B

Bob Powell [MVP]

Are you directly using the LayeredWindow API?

--
--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.


Brian R. said:
So how do I disable the OnPaintBackground? I tried overriding
OnPaintBackground but it never gets called. I tried setting window styles
to
UserPaint and AllPaintingInWMPaint, but that didn't make either OnPaint or
OnPaintBackground get called.

Could this be related to layered windows? I read something about the .NET
transition to a layered window has an error that causes flicker. The
workaround was to set a transparent key color, which forces .NET to layer
the
window. This solved the flicker problem, BUT it made the window insanely
slow to transition, esepcially when maximized.
 
G

Guest

No. All I did was set the .NET Windows Form property: TransparencyKey. That
got rid of the flicker but made the window fade SO Much slower. The article
I read stated that this property, when set, forces System.Windows.Forms to
layer the window.

See the last section from this code project article that addresses opacity
and layered windows.

http://www.codeproject.com/csharp/notanotherformfader.asp
 
L

Linda Liu [MSFT]

Hi Brian,

Thank you for your sample project.

I run it on my machine and see the TransitionForm flashes when it is
closed. I have a try setting the TransparencyKey property of the
TransitionForm to Lime, and see that the flicker is eliminated.

But I don't see the transition becomes slower after I set the
TransitionForm's TransparencyKey property.

I think a simple workaround to this slow transition problem is to decrease
the transition range of the Opacity, e.g. from 0.5 to 1 and then from 1 to
0.5. To do this, you can set the TransitionForm's Opacity property to 0.5
in the designer and modify one line of code in the FadeInTimerElapsed
method as follows:

// modify the original line of code
if (Opacity <= 0.0)
// to the code below
if (Opacity <=0.5)

Hope this helps.
If you have any concern, please feel free to let me know.


Sincerely,
Linda Liu
Microsoft Online Community Support
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top