调用EnableScrollBar时滚动条闪烁 [英] Scrollbar flicker when calling EnableScrollBar

查看:128
本文介绍了调用EnableScrollBar时滚动条闪烁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用p/调用从user32.dll调用EnableScrollBar(

I'm using p/invoke to call EnableScrollBar from user32.dll (MSDN reference). I noticed that when the scrollbar is enabled, it seems to draw as though no theme is applied and then re-drawn with the theme applied. I've only tested with Windows 7 so far. Is there any way to stop this from happening?

编辑:下面是一些代码,显示发生了什么(转储到带有滚动条的表单中):

Here's some code to show what happens (dump into a form with scrollbars):

private class Native
{
    [DllImport("user32.dll")]
    public static extern bool EnableScrollBar(IntPtr hWnd, uint wSBflags, uint wArrows);

    public static class SBArrows
    {
        public const uint ESB_ENABLE_BOTH = 0;
        public const uint ESB_DISABLE_BOTH = 3;
        public const uint ESB_DISABLE_LEFT = 1;
        public const uint ESB_DISABLE_RIGHT = 2;
        public const uint ESB_DISABLE_UP = 1;
        public const uint ESB_DISABLE_DOWN = 2;
        public const uint ESB_DISABLE_LTUP = 1;
        public const uint ESB_DISABLE_RTDN = 2;
    }

    public static class SBFlags
    {
        public const uint SB_HORZ = 0;
        public const uint SB_VERT = 1;
        public const uint SB_CTL = 2;
        public const uint SB_BOTH = 3;
    }
}


private bool Switch = false;

protected override void OnMouseDown(MouseEventArgs e)
{
    Native.EnableScrollBar(this.Handle, Native.SBFlags.SB_HORZ, this.Switch ? Native.SBArrows.ESB_DISABLE_BOTH : Native.SBArrows.ESB_ENABLE_BOTH);
    this.Switch = !this.Switch;
}


Native.SendMessage(this.Handle, Native.WindowMessages.WM_SETREDRAW, new IntPtr(0), IntPtr.Zero);
Native.EnableScrollBar(this.Handle, Native.SBFlags.SB_HORZ, Native.SBArrows.ESB_ENABLE_BOTH);
Native.SendMessage(this.Handle, Native.WindowMessages.WM_SETREDRAW, new IntPtr(1), IntPtr.Zero);

推荐答案

我不太喜欢这种解决方案.但是它确实起作用:

I don't like this solution much. It does however work:

    protected override void OnMouseDown(MouseEventArgs e) {
        Native.LockWindowUpdate(this.Handle);
        Native.EnableScrollBar(this.Handle, Native.SBFlags.SB_HORZ, this.Switch ? Native.SBArrows.ESB_DISABLE_BOTH : Native.SBArrows.ESB_ENABLE_BOTH);
        //this.Invalidate();
        Native.LockWindowUpdate(IntPtr.Zero);
        this.Switch = !this.Switch;
    }

这篇关于调用EnableScrollBar时滚动条闪烁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆