views:

558

answers:

3

Hello,

Does anyone know of any way to suppress the Vista fade animations on scroll bars?

I only want to do this temporarily and I don't think subclassing is an option because the scroll bars are the "automatic" ones generated by the auto-scroll functionality (it's a .NET app but I assume interop is required).

The reason I want to do this is because the content of the control can (and will) change and cause the vertical scroll bar to be automatically hidden. However - and this is the part that's been driving me crazy - if the user has hovered over the scroll bar within the last 1-2 seconds and the animation is still in progress, then the scroll bar hides but the animation continues anyway and leaves a ghost image, so the SB appears to still be there even though it really isn't (can't click on it, and minimizing/restoring the form makes it disappear completely).

I'm figuring that Vista uses some sort of timer for this animation and hoping that maybe there's some new API to stop the timer (Google is unfortunately no help on this). Or if anybody else has encountered this problem and knows a different way to solve it, that would be great too.

Thanks in advance,
Aaron

A: 

Is there any reason to have scrollbars at all? You can turn them off without using any Win32 API tricks, while also setting the size of your window to appropriately handle the animation (or scaling your animation).

I think your only other option is to roll your own Window object, which would be a royal pain.

Jess
Too much content to fit on the form without scrolling. Not good to restrict the large content to its own scroll box because it would end up being a very small usable area. Think of a report with a long header/footer - you generally want to scroll the entire report, not just the main body.
Aaronaught
A: 

Hello Aaron,

this is an effect I'm also wondering about.

I wrote a control derived from ContainerControl where the child controls may grow or shrink by user interaction. So I spent some time to set up my own LayoutEngine to get the needed layout for the child controls. But even this animated non-stopping SB is dirty. I have a workaround - please don't take it as a solution - in the Layout method I set the focus on the container control before making the layout. That works for me...

rp

Another workaround...

is to inherit from the ScrollableControl (Panel, ...) and to

override the WndProc method and use the PreventScrollAnimation method. This will eat all WM_NCMOUSEMOVE messages having a hit test in the scroll bar. So this will prevent the internals to start the fading of the scroll bar. BTW the fading is implemented in the VISTA-UI using a timer callback, so there is no possibility to stop it.

const int WM_NCMOUSEMOVE = 160;
const int HTHSCROLL = 6;
const int HTVSCROLL = 7;

bool PreventScrollAnimation(ref Message m)
{
 if (m.Msg == WM_NCMOUSEMOVE)
 {
  if ((m.WParam.ToInt32() == HTHSCROLL) ||
   (m.WParam.ToInt32() == HTVSCROLL))
  {
   m.Result = IntPtr.Zero;
   return true;
  }
 }
 return false;
}

protected override void WndProc(ref Message m)
{
 if (PreventScrollAnimation(ref m))
  return;

 base.WndProc(ref m);
}
A: 

The question doesn't make it entirely clear if you are referring to scroll bars within your application or system wide. If you are referring to system wide, then I'm not sure what you could do other than a whole new theme for your whole computer. However, if you are referring to changing just your own application, you can modify scroll bar behavior using WPF control templates to do what you are describing.

If you have Expression Blend, it is pretty easy to do because it can create a copy of the default scroll bar which you can modify to suit your tastes (such as changing timing of fades to zero in this case). This link isn't exactly what you are looking for but it should give you a sense of what that might involve.

If you don't have Expression Blend, it is still possible to code the same thing by hand since it's all just XAML text (even when Blend produces it) but it will take some more effort to learn how to do it that way.

Chapter 15 of Windows Presentation Foundation Unleashed (a great book for many reasons) explains how to use WPF within and as a host of Win32 and Windows Forms apps, which is handy if you are unable to port your entire app to WPF but still want to use some WPF features selectively.

Eric Cosky
It's just within the application and specifically within one control; it autosizes itself inside another control, but the parent scroll bar doesn't go away when it should if it's in the middle of an animation. It's also a Winforms 2.0 app - don't have WPF - might investigate embedding.
Aaronaught