private void UpdateScrollValues() { WinApi.SCROLLBARINFO psbi = new WinApi.SCROLLBARINFO(); psbi.cbSize = Marshal.SizeOf(psbi); WinApi.GetScrollBarInfo(m_ParentScrollBar.Handle, (uint)WinApi.eObjectId.OBJID_CLIENT, ref psbi); Rectangle displayRect = new Rectangle(0, 0, m_ParentScrollBar.Width, m_ParentScrollBar.Height); if (IsVScroll) { if (m_ScrollBarCore.DisplayRectangle != displayRect) m_ScrollBarCore.DisplayRectangle = displayRect; Rectangle thumbRect = new Rectangle(displayRect.X, displayRect.Y, displayRect.Width, psbi.dxyLineButton); if (m_ScrollBarCore.ThumbDecreaseRectangle != thumbRect) m_ScrollBarCore.ThumbDecreaseRectangle = thumbRect; thumbRect = new Rectangle(displayRect.X, displayRect.Bottom - psbi.dxyLineButton, displayRect.Width, psbi.dxyLineButton); if (m_ScrollBarCore.ThumbIncreaseRectangle != thumbRect) m_ScrollBarCore.ThumbIncreaseRectangle = thumbRect; thumbRect = new Rectangle(displayRect.X, displayRect.Y + psbi.xyThumbTop, displayRect.Width, psbi.xyThumbBottom - psbi.xyThumbTop); if (m_ScrollBarCore.TrackRectangle != thumbRect) m_ScrollBarCore.TrackRectangle = thumbRect; } else { if (m_ScrollBarCore.DisplayRectangle != displayRect) m_ScrollBarCore.DisplayRectangle = displayRect; Rectangle thumbRect = new Rectangle(displayRect.X, displayRect.Y, psbi.dxyLineButton, displayRect.Height); if (m_ScrollBarCore.ThumbDecreaseRectangle != thumbRect) m_ScrollBarCore.ThumbDecreaseRectangle = thumbRect; thumbRect = new Rectangle(displayRect.Right - psbi.dxyLineButton, displayRect.Y, psbi.dxyLineButton, displayRect.Height); if (m_ScrollBarCore.ThumbIncreaseRectangle != thumbRect) m_ScrollBarCore.ThumbIncreaseRectangle = thumbRect; thumbRect = new Rectangle(displayRect.X + psbi.xyThumbTop, displayRect.Y, psbi.xyThumbBottom - psbi.xyThumbTop, displayRect.Height); if (m_ScrollBarCore.TrackRectangle != thumbRect) m_ScrollBarCore.TrackRectangle = thumbRect; } if (m_ScrollBarCore.Minimum != m_ParentScrollBar.Minimum) m_ScrollBarCore.Minimum = m_ParentScrollBar.Minimum; if (m_ScrollBarCore.Maximum != m_ParentScrollBar.Maximum) m_ScrollBarCore.Maximum = m_ParentScrollBar.Maximum; if (m_ScrollBarCore.SmallChange != m_ParentScrollBar.SmallChange) m_ScrollBarCore.SmallChange = m_ParentScrollBar.SmallChange; if (m_ScrollBarCore.LargeChange != m_ParentScrollBar.LargeChange) m_ScrollBarCore.LargeChange = m_ParentScrollBar.LargeChange; if (m_ScrollBarCore.Value != m_ParentScrollBar.Value) m_ScrollBarCore.Value = m_ParentScrollBar.Value; }
//private void PaintUnBuffered() //{ // IntPtr dc = WinApi.GetWindowDC(m_Control.Handle); // try // { // using (Graphics g = Graphics.FromHdc(dc)) // { // g.SetClip(GetClientRectangle(), CombineMode.Exclude); // if (!ShouldSkinScrollbars) // { // WinApi.SCROLLBARINFO psbi = new WinApi.SCROLLBARINFO(); // psbi.cbSize = Marshal.SizeOf(psbi); // WinApi.GetScrollBarInfo(m_Control.Handle, (uint)WinApi.eObjectId.OBJID_VSCROLL, ref psbi); // if (psbi.rgstate[0] != (int)WinApi.eStateFlags.STATE_SYSTEM_INVISIBLE) // { // Rectangle rvs = ScreenToNonClientRectangle(psbi.rcScrollBar.ToRectangle()); // g.SetClip(rvs, System.Drawing.Drawing2D.CombineMode.Exclude); // } // psbi = new WinApi.SCROLLBARINFO(); // psbi.cbSize = Marshal.SizeOf(psbi); // WinApi.GetScrollBarInfo(m_Control.Handle, (uint)WinApi.eObjectId.OBJID_HSCROLL, ref psbi); // if (psbi.rgstate[0] != (int)WinApi.eStateFlags.STATE_SYSTEM_INVISIBLE) // { // Rectangle rvs = ScreenToNonClientRectangle(psbi.rcScrollBar.ToRectangle()); // g.SetClip(rvs, System.Drawing.Drawing2D.CombineMode.Exclude); // } // } // PaintNonClientArea(g); // g.ResetClip(); // } // } // finally // { // WinApi.ReleaseDC(m_Control.Handle, dc); // } //} private void RenderNonClientAreaBitmap(BufferedBitmap bmp) { if (bmp == null) return; IntPtr dc = WinApi.GetWindowDC(m_Control.Handle); try { using (Graphics g = Graphics.FromHdc(dc)) { Rectangle[] clips = new Rectangle[3]; clips[0] = GetClientRectangle(); if (!ShouldSkinScrollbars) { WinApi.SCROLLBARINFO psbi = new WinApi.SCROLLBARINFO(); psbi.cbSize = Marshal.SizeOf(psbi); WinApi.GetScrollBarInfo(m_Control.Handle, (uint)WinApi.eObjectId.OBJID_VSCROLL, ref psbi); if (psbi.rgstate[0] != (int)WinApi.eStateFlags.STATE_SYSTEM_INVISIBLE) { Rectangle rvs = ScreenToNonClientRectangle(psbi.rcScrollBar.ToRectangle()); clips[1] = rvs; } psbi = new WinApi.SCROLLBARINFO(); psbi.cbSize = Marshal.SizeOf(psbi); WinApi.GetScrollBarInfo(m_Control.Handle, (uint)WinApi.eObjectId.OBJID_HSCROLL, ref psbi); if (psbi.rgstate[0] != (int)WinApi.eStateFlags.STATE_SYSTEM_INVISIBLE) { Rectangle rvs = ScreenToNonClientRectangle(psbi.rcScrollBar.ToRectangle()); clips[2] = rvs; } } bmp.Render(g, clips); } } finally { WinApi.ReleaseDC(m_Control.Handle, dc); } }
public void UpdateScrollValues() { if (!ShouldSkinScrollbars) return; WinApi.SCROLLBARINFO psbi = new WinApi.SCROLLBARINFO(); psbi.cbSize = Marshal.SizeOf(psbi); WinApi.GetScrollBarInfo(m_Control.Handle, (uint)WinApi.eObjectId.OBJID_VSCROLL, ref psbi); if (psbi.rgstate[0] != (int)WinApi.eStateFlags.STATE_SYSTEM_INVISIBLE) { Rectangle displayRect = ScreenToNonClientRectangle(psbi.rcScrollBar.ToRectangle()); if (m_VScrollBar.DisplayRectangle != displayRect) m_VScrollBar.DisplayRectangle = displayRect; Rectangle thumbRect = new Rectangle(displayRect.X, displayRect.Y, displayRect.Width, psbi.dxyLineButton); if (m_VScrollBar.ThumbDecreaseRectangle != thumbRect) m_VScrollBar.ThumbDecreaseRectangle = thumbRect; thumbRect = new Rectangle(displayRect.X, displayRect.Bottom - psbi.dxyLineButton, displayRect.Width, psbi.dxyLineButton); if (m_VScrollBar.ThumbIncreaseRectangle != thumbRect) m_VScrollBar.ThumbIncreaseRectangle = thumbRect; thumbRect = new Rectangle(displayRect.X, displayRect.Y + psbi.xyThumbTop, displayRect.Width, psbi.xyThumbBottom - psbi.xyThumbTop); if (m_VScrollBar.TrackRectangle != thumbRect) m_VScrollBar.TrackRectangle = thumbRect; if (psbi.rgstate[0] == (int)WinApi.eStateFlags.STATE_SYSTEM_UNAVAILABLE) { if (m_VScrollBar.Enabled) m_VScrollBar.Enabled = false; } else if (!m_VScrollBar.Enabled) m_VScrollBar.Enabled = true; m_VScrollBar.Visible = true; } else m_VScrollBar.Visible = false; // Horizontal scroll bar psbi = new WinApi.SCROLLBARINFO(); psbi.cbSize = Marshal.SizeOf(psbi); WinApi.GetScrollBarInfo(m_Control.Handle, (uint)WinApi.eObjectId.OBJID_HSCROLL, ref psbi); if (psbi.rgstate[0] != (int)WinApi.eStateFlags.STATE_SYSTEM_INVISIBLE) { Rectangle displayRect = ScreenToNonClientRectangle(psbi.rcScrollBar.ToRectangle()); if (m_HScrollBar.DisplayRectangle != displayRect) m_HScrollBar.DisplayRectangle = displayRect; Rectangle thumbRect = new Rectangle(displayRect.X, displayRect.Y, psbi.dxyLineButton, displayRect.Height); if (m_HScrollBar.ThumbDecreaseRectangle != thumbRect) m_HScrollBar.ThumbDecreaseRectangle = thumbRect; thumbRect = new Rectangle(displayRect.Right - psbi.dxyLineButton, displayRect.Y, psbi.dxyLineButton, displayRect.Height); if (m_HScrollBar.ThumbIncreaseRectangle != thumbRect) m_HScrollBar.ThumbIncreaseRectangle = thumbRect; thumbRect = new Rectangle(displayRect.X + psbi.xyThumbTop, displayRect.Y, psbi.xyThumbBottom - psbi.xyThumbTop, displayRect.Height); if (m_HScrollBar.TrackRectangle != thumbRect) m_HScrollBar.TrackRectangle = thumbRect; if (psbi.rgstate[0] == (int)WinApi.eStateFlags.STATE_SYSTEM_UNAVAILABLE) { if (m_HScrollBar.Enabled) m_VScrollBar.Enabled = false; } else if (!m_HScrollBar.Enabled) m_HScrollBar.Enabled = true; m_HScrollBar.Visible = true; } else m_HScrollBar.Visible = false; }
protected virtual void UpdateScrollBars() { if (!IsHandleCreated || _UpdatingScrollbars) return; _UpdatingScrollbars = true; try { Control scrollOverrideControl = _ScrollOverrideControl; if (scrollOverrideControl == null) { if (_HScrollBar.Visible) _HScrollBar.Visible = false; if (_VScrollBar.Visible) _VScrollBar.Visible = false; return; } WinApi.SCROLLBARINFO psbi = new WinApi.SCROLLBARINFO(); psbi.cbSize = Marshal.SizeOf(psbi); WinApi.GetScrollBarInfo(scrollOverrideControl.Handle, (uint)WinApi.eObjectId.OBJID_VSCROLL, ref psbi); if (psbi.rgstate[0] != (int)WinApi.eStateFlags.STATE_SYSTEM_INVISIBLE) { Rectangle vsBounds = psbi.rcScrollBar.ToRectangle(); vsBounds.Location = this.PointToClient(vsBounds.Location); Rectangle scrollCountrolBounds = _ScrollOverrideControl.Bounds; if (!scrollCountrolBounds.Contains(vsBounds)) { // We need to guess bounds for best performance and appearance if (vsBounds.Right > scrollCountrolBounds.Right) { vsBounds.X = scrollCountrolBounds.Right - vsBounds.Width; } else if (vsBounds.X < scrollCountrolBounds.X) { vsBounds.X = 0; } } if (_VScrollBar.Bounds != vsBounds) { _VScrollBar.Bounds = vsBounds; UpdateVerticalScrollBarValues(); } if (!_VScrollBar.Visible) { _VScrollBar.Visible = true; _VScrollBar.Refresh(); InvokeDelayed(new MethodInvoker(delegate { UpdateVerticalScrollBarValues(); }), ScrollPositionUpdateDelay); } if (psbi.rgstate[0] == (int)WinApi.eStateFlags.STATE_SYSTEM_UNAVAILABLE) _VScrollBar.Enabled = false; else if (!_VScrollBar.Enabled) _VScrollBar.Enabled = true; //Console.WriteLine("VscrollBar Bounds detection {0}", vsBounds); } else if (_VScrollBar.Visible) _VScrollBar.Visible = false; psbi = new WinApi.SCROLLBARINFO(); psbi.cbSize = Marshal.SizeOf(psbi); WinApi.GetScrollBarInfo(scrollOverrideControl.Handle, (uint)WinApi.eObjectId.OBJID_HSCROLL, ref psbi); if (psbi.rgstate[0] != (int)WinApi.eStateFlags.STATE_SYSTEM_INVISIBLE) { Rectangle hsBounds = psbi.rcScrollBar.ToRectangle(); hsBounds.Location = this.PointToClient(hsBounds.Location); Rectangle scrollCountrolBounds = _ScrollOverrideControl.Bounds; if (!scrollCountrolBounds.Contains(hsBounds)) { // We need to guess bounds for best performance and appearance if (hsBounds.Bottom > scrollCountrolBounds.Bottom) { hsBounds.Y = scrollCountrolBounds.Bottom - hsBounds.Height; } } if (_VScrollBar.Visible && hsBounds.Width == scrollCountrolBounds.Width) hsBounds.Width -= _VScrollBar.Width; if (_HScrollBar.Bounds != hsBounds) { _HScrollBar.Bounds = hsBounds; UpdateHorizontalScrollBarValues(); } if (!_HScrollBar.Visible) { _HScrollBar.Visible = true; _HScrollBar.Refresh(); InvokeDelayed(new MethodInvoker(delegate { UpdateHorizontalScrollBarValues(); }), ScrollPositionUpdateDelay); } if (psbi.rgstate[0] == (int)WinApi.eStateFlags.STATE_SYSTEM_UNAVAILABLE) _HScrollBar.Enabled = false; else if (!_HScrollBar.Enabled) _HScrollBar.Enabled = true; } else if (_HScrollBar.Visible) _HScrollBar.Visible = false; if (_HScrollBar.Visible && _VScrollBar.Visible) { _Thumb.Bounds = new Rectangle(_VScrollBar.Left, _VScrollBar.Bounds.Bottom, _VScrollBar.Width, _HScrollBar.Height); _Thumb.Visible = true; } else { _Thumb.Visible = false; } } finally { _UpdatingScrollbars = false; } }