代码之家  ›  专栏  ›  技术社区  ›  TheCloudlessSky

调用EnableScrollBar时滚动条闪烁

  •  0
  • TheCloudlessSky  · 技术社区  · 16 年前

    我用p/invoke来调用 EnableScrollBar 从 user32.dll ( MSDN reference ). 我注意到,当滚动条被启用时,它看起来就像没有应用主题一样绘制,然后用应用的主题重新绘制。到目前为止,我只测试过Windows7。有

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

    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);
    
    1 回复  |  直到 16 年前
        1
  •  2
  •   Hans Passant    16 年前

        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;
        }
    
    推荐文章