Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / June 2007

Tip: Looking for answers? Try searching our database.

Fade Transition Trick

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Brian R. - 07 Jun 2007 17:11 GMT
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.

Signature

Brian R.

Bob Powell [MVP] - 07 Jun 2007 22:07 GMT
For almost any reasonably intellient paint scheme one should disable the
OnPaintBackground.

Signature

--
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.

> We are trying to use basic windows forms to do "fancy" transitions on our
> application.  When switching between main form controls (docked to full),
[quoted text clipped - 32 lines]
> Any thougths would be helpful.  I am sure I am missing some vital step
> here.
Brian R. - 07 Jun 2007 22:17 GMT
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.

Signature

Brian R.

> For almost any reasonably intellient paint scheme one should disable the
> OnPaintBackground.
[quoted text clipped - 35 lines]
> > Any thougths would be helpful.  I am sure I am missing some vital step
> > here.
Linda Liu [MSFT] - 08 Jun 2007 07:58 GMT
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.
Bob Powell [MVP] - 08 Jun 2007 09:26 GMT
Are you directly using the LayeredWindow API?

Signature

--
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.

> So how do I disable the OnPaintBackground?  I tried overriding
> OnPaintBackground but it never gets called.  I tried setting window styles
[quoted text clipped - 55 lines]
>> > Any thougths would be helpful.  I am sure I am missing some vital step
>> > here.
Brian R. - 08 Jun 2007 14:41 GMT
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

Signature

Brian R.

> Are you directly using the LayeredWindow API?
>
[quoted text clipped - 57 lines]
> >> > Any thougths would be helpful.  I am sure I am missing some vital step
> >> > here.
Linda Liu [MSFT] - 13 Jun 2007 05:00 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.