private void DrawScrollBar(IntPtr maskHWnd, Rectangle bounds, Rectangle trackRect, Rectangle topLeftArrowRect, Rectangle bottomRightArrowRect, Rectangle thumbRect, ControlState topLeftArrowState, ControlState bottomRightArrowState, ControlState thumbState, Orientation direction) { bool flag = direction == Orientation.Horizontal; bool enabled = this._owner.Enabled; IScrollBarPaint paint = this._owner as IScrollBarPaint; if (paint != null) { ImageDc dc = new ImageDc(bounds.Width, bounds.Height); IntPtr dC = Win32.NativeMethods.GetDC(maskHWnd); try { using (Graphics graphics = Graphics.FromHdc(dc.Hdc)) { using (TCEventArgs.PaintScrollBarTrackEventArgs args = new TCEventArgs.PaintScrollBarTrackEventArgs(graphics, trackRect, direction, enabled)) { paint.OnPaintScrollBarTrack(args); } ArrowDirection arrowDirection = flag ? ArrowDirection.Left : ArrowDirection.Up; using (TCEventArgs.PaintScrollBarArrowEventArgs args2 = new TCEventArgs.PaintScrollBarArrowEventArgs(graphics, topLeftArrowRect, topLeftArrowState, arrowDirection, direction, enabled)) { paint.OnPaintScrollBarArrow(args2); } arrowDirection = flag ? ArrowDirection.Right : ArrowDirection.Down; using (TCEventArgs.PaintScrollBarArrowEventArgs args3 = new TCEventArgs.PaintScrollBarArrowEventArgs(graphics, bottomRightArrowRect, bottomRightArrowState, arrowDirection, direction, enabled)) { paint.OnPaintScrollBarArrow(args3); } using (TCEventArgs.PaintScrollBarThumbEventArgs args4 = new TCEventArgs.PaintScrollBarThumbEventArgs(graphics, thumbRect, thumbState, direction, enabled)) { paint.OnPaintScrollBarThumb(args4); } } Win32.NativeMethods.BitBlt(dC, 0, 0, bounds.Width, bounds.Height, dc.Hdc, 0, 0, 0xcc0020); } finally { Win32.NativeMethods.ReleaseDC(maskHWnd, dC); dc.Dispose(); } } }
private void DrawScrollBar( IntPtr maskHWnd, Rectangle bounds, Rectangle trackRect, Rectangle topLeftArrowRect, Rectangle bottomRightArrowRect, Rectangle thumbRect, ControlState topLeftArrowState, ControlState bottomRightArrowState, ControlState thumbState, Orientation direction) { bool bHorizontal = direction == Orientation.Horizontal; ArrowDirection arrowDirection; bool bEnabled = _owner.Enabled; IScrollBarPaint paint = _owner as IScrollBarPaint; if (paint == null) { return; } ImageDc tempDc = new ImageDc(bounds.Width, bounds.Height); IntPtr hdc = NativeMethods.GetDC(maskHWnd); try { using (Graphics g = Graphics.FromHdc(tempDc.Hdc)) { using (PaintScrollBarTrackEventArgs te = new PaintScrollBarTrackEventArgs( g, trackRect, direction, bEnabled)) { Graphics ge = te.Graphics; Rectangle rect = te.TrackRectangle; Color baseColor = GetGray(Color.Blue); ControlPaintEx.DrawScrollBarTrack( ge, rect, baseColor, Color.White, te.Orientation); //paint.OnPaintScrollBarTrack(te); } arrowDirection = bHorizontal ? ArrowDirection.Left : ArrowDirection.Up; using (PaintScrollBarArrowEventArgs te = new PaintScrollBarArrowEventArgs( g, topLeftArrowRect, topLeftArrowState, arrowDirection, direction, bEnabled)) { paint.OnPaintScrollBarArrow(te); } arrowDirection = bHorizontal ? ArrowDirection.Right : ArrowDirection.Down; using (PaintScrollBarArrowEventArgs te = new PaintScrollBarArrowEventArgs( g, bottomRightArrowRect, bottomRightArrowState, arrowDirection, direction, bEnabled)) { paint.OnPaintScrollBarArrow(te); } using (PaintScrollBarThumbEventArgs te = new PaintScrollBarThumbEventArgs( g, thumbRect, thumbState, direction, bEnabled)) { paint.OnPaintScrollBarThumb(te); } } NativeMethods.BitBlt( hdc, 0, 0, bounds.Width, bounds.Height, tempDc.Hdc, 0, 0, TernaryRasterOperations.SRCCOPY); } finally { NativeMethods.ReleaseDC(maskHWnd, hdc); tempDc.Dispose(); } }