/// <summary> /// Draws an arrow button. /// </summary> /// <param name="g">The <see cref="Graphics"/> used to paint.</param> /// <param name="rect">The rectangle in which to paint.</param> /// <param name="state">The <see cref="ScrollBarArrowButtonState"/> of the arrow button.</param> /// <param name="arrowUp">true for an up arrow, false otherwise.</param> private static void DrawArrowButtonVertical( Graphics g, Rectangle rect, ScrollBarArrowButtonState state, bool arrowUp) { using (Image arrowImage = GetArrowDownButtonImage(state)) { if (arrowUp) { arrowImage.RotateFlip(RotateFlipType.Rotate180FlipNone); } g.DrawImage(arrowImage, rect); } }
public static void DrawArrowButton(Graphics g, Rectangle bounds, ScrollBarArrowButtonState state) { if (!IsSupported) { throw new InvalidOperationException(); } VisualStyleRenderer vsr; switch (state) { case ScrollBarArrowButtonState.DownDisabled: vsr = new VisualStyleRenderer(VisualStyleElement.ScrollBar.ArrowButton.DownDisabled); break; case ScrollBarArrowButtonState.DownHot: vsr = new VisualStyleRenderer(VisualStyleElement.ScrollBar.ArrowButton.DownHot); break; case ScrollBarArrowButtonState.DownNormal: default: vsr = new VisualStyleRenderer(VisualStyleElement.ScrollBar.ArrowButton.DownNormal); break; case ScrollBarArrowButtonState.DownPressed: vsr = new VisualStyleRenderer(VisualStyleElement.ScrollBar.ArrowButton.DownPressed); break; case ScrollBarArrowButtonState.LeftDisabled: vsr = new VisualStyleRenderer(VisualStyleElement.ScrollBar.ArrowButton.LeftDisabled); break; case ScrollBarArrowButtonState.LeftHot: vsr = new VisualStyleRenderer(VisualStyleElement.ScrollBar.ArrowButton.LeftHot); break; case ScrollBarArrowButtonState.LeftNormal: vsr = new VisualStyleRenderer(VisualStyleElement.ScrollBar.ArrowButton.LeftNormal); break; case ScrollBarArrowButtonState.LeftPressed: vsr = new VisualStyleRenderer(VisualStyleElement.ScrollBar.ArrowButton.LeftPressed); break; case ScrollBarArrowButtonState.RightDisabled: vsr = new VisualStyleRenderer(VisualStyleElement.ScrollBar.ArrowButton.RightDisabled); break; case ScrollBarArrowButtonState.RightHot: vsr = new VisualStyleRenderer(VisualStyleElement.ScrollBar.ArrowButton.RightHot); break; case ScrollBarArrowButtonState.RightNormal: vsr = new VisualStyleRenderer(VisualStyleElement.ScrollBar.ArrowButton.RightNormal); break; case ScrollBarArrowButtonState.RightPressed: vsr = new VisualStyleRenderer(VisualStyleElement.ScrollBar.ArrowButton.RightPressed); break; case ScrollBarArrowButtonState.UpDisabled: vsr = new VisualStyleRenderer(VisualStyleElement.ScrollBar.ArrowButton.UpDisabled); break; case ScrollBarArrowButtonState.UpHot: vsr = new VisualStyleRenderer(VisualStyleElement.ScrollBar.ArrowButton.UpHot); break; case ScrollBarArrowButtonState.UpNormal: vsr = new VisualStyleRenderer(VisualStyleElement.ScrollBar.ArrowButton.UpNormal); break; case ScrollBarArrowButtonState.UpPressed: vsr = new VisualStyleRenderer(VisualStyleElement.ScrollBar.ArrowButton.UpPressed); break; } vsr.DrawBackground(g, bounds); }
/// <summary> /// Draws an arrow button. /// </summary> /// <param name="g">The <see cref="Graphics"/> used to paint.</param> /// <param name="rect">The rectangle in which to paint.</param> /// <param name="state">The <see cref="ScrollBarArrowButtonState"/> of the arrow button.</param> /// <param name="arrowUp">true for an up arrow, false otherwise.</param> /// <param name="orientation">The <see cref="ScrollBarOrientation"/>.</param> public static void DrawArrowButton( Graphics g, Rectangle rect, ScrollBarArrowButtonState state, bool arrowUp, ScrollBarOrientation orientation) { if (g == null) { throw new ArgumentNullException("g"); } if (rect.IsEmpty || g.IsVisibleClipEmpty || !g.VisibleClipBounds.IntersectsWith(rect)) { return; } if (orientation == ScrollBarOrientation.Vertical) { DrawArrowButtonVertical(g, rect, state, arrowUp); } else { DrawArrowButtonHorizontal(g, rect, state, arrowUp); } }
/// <summary> /// Resets the scroll status of the scrollbar. /// </summary> private void ResetScrollStatus() { // get current mouse position Point pos = this.PointToClient(Cursor.Position); // set appearance of buttons in relation to where the mouse is - // outside or inside the control if (this.ClientRectangle.Contains(pos)) { this.bottomButtonState = ScrollBarArrowButtonState.DownActive; this.topButtonState = ScrollBarArrowButtonState.UpActive; } else { this.bottomButtonState = ScrollBarArrowButtonState.DownNormal; this.topButtonState = ScrollBarArrowButtonState.UpNormal; } // set appearance of thumb this.thumbState = this.thumbRectangle.Contains(pos) ? ScrollBarState.Hot : ScrollBarState.Normal; this.bottomArrowClicked = this.bottomBarClicked = this.topArrowClicked = this.topBarClicked = false; this.StopTimer(); this.Refresh(); }
/// <summary> /// Draws an arrow button. /// </summary> /// <param name="g">The <see cref="Graphics"/> used to paint.</param> /// <param name="rect">The rectangle in which to paint.</param> /// <param name="state">The <see cref="ScrollBarArrowButtonState"/> of the arrow button.</param> /// <param name="arrowUp">true for an up arrow, false otherwise.</param> private void DrawArrowButtonHorizontal(Graphics g, Rectangle rect, ScrollBarArrowButtonState state, bool arrowUp) { var pressed = state == ScrollBarArrowButtonState.DownPressed || state == ScrollBarArrowButtonState.UpPressed; using (Brush brush = new SolidBrush(pressed ? foreColorActive : foreColor)) { Point[] arrow; Int32 pad = 0; Point middle = new Point(rect.Left + rect.Width / 2, rect.Top + rect.Height / 2); switch (arrowUp) { case true: pad = ScaleHelper.Scale(2); arrow = new Point[] { new Point(middle.X + pad, middle.Y - 2 * pad), new Point(middle.X + pad, middle.Y + 2 * pad), new Point(middle.X - pad, middle.Y) }; break; default: pad = ScaleHelper.Scale(2); arrow = new Point[] { new Point(middle.X - pad, middle.Y - 2 * pad), new Point(middle.X - pad, middle.Y + 2 * pad), new Point(middle.X + pad, middle.Y) }; break; } g.FillPolygon(brush, arrow); } }
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] // Using Graphics instead of IDeviceContext intentionally public static void DrawArrowButton(Graphics g, Rectangle bounds, ScrollBarArrowButtonState state) { InitializeRenderer(VisualStyleElement.ScrollBar.ArrowButton.LeftNormal, (int)state); visualStyleRenderer.DrawBackground(g, bounds); }
/// <summary> /// Draws the arrow down button for the scrollbar. /// </summary> /// <param name="state">The button state.</param> /// <returns>The arrow down button as <see cref="Image"/>.</returns> private static Image GetArrowDownButtonImage( ScrollBarArrowButtonState state) { Rectangle rect = new Rectangle(0, 0, 15, 17); Bitmap bitmap = new Bitmap(15, 17, PixelFormat.Format32bppArgb); bitmap.SetResolution(72f, 72f); using (Graphics g = Graphics.FromImage(bitmap)) { g.SmoothingMode = SmoothingMode.None; g.InterpolationMode = InterpolationMode.Low; int index = -1; switch (state) { case ScrollBarArrowButtonState.UpHot: case ScrollBarArrowButtonState.DownHot: { index = 1; break; } //-- Added normal cases here (if you want to).. //case ScrollBarArrowButtonState.UpNormal: //case ScrollBarArrowButtonState.DownNormal: case ScrollBarArrowButtonState.UpActive: case ScrollBarArrowButtonState.DownActive: { index = 0; break; } case ScrollBarArrowButtonState.UpPressed: case ScrollBarArrowButtonState.DownPressed: { index = 2; break; } } if (index != -1) { using (Pen p1 = new Pen(arrowBorderColors[0]), p2 = new Pen(arrowBorderColors[1])) { g.DrawLine(p1, rect.X, rect.Y, rect.Right - 1, rect.Y); g.DrawLine(p2, rect.X, rect.Bottom - 1, rect.Right - 1, rect.Bottom - 1); } rect.Inflate(0, -1); using (LinearGradientBrush brush = new LinearGradientBrush( rect, arrowBorderColors[2], arrowBorderColors[1], LinearGradientMode.Vertical)) { ColorBlend blend = new ColorBlend(3) { Positions = new[] { 0f, .5f, 1f }, Colors = new[] { arrowBorderColors[2], arrowBorderColors[3], arrowBorderColors[0] } }; brush.InterpolationColors = blend; using (Pen p = new Pen(brush)) { g.DrawLine(p, rect.X, rect.Y, rect.X, rect.Bottom - 1); g.DrawLine(p, rect.Right - 1, rect.Y, rect.Right - 1, rect.Bottom - 1); } } rect.Inflate(0, 1); Rectangle upper = rect; upper.Inflate(-1, 0); upper.Y++; upper.Height = 7; using (LinearGradientBrush brush = new LinearGradientBrush( upper, arrowColors[index, 2], arrowColors[index, 3], LinearGradientMode.Vertical)) { g.FillRectangle(brush, upper); } upper.Inflate(-1, 0); upper.Height = 6; using (LinearGradientBrush brush = new LinearGradientBrush( upper, arrowColors[index, 0], arrowColors[index, 1], LinearGradientMode.Vertical)) { g.FillRectangle(brush, upper); } Rectangle lower = rect; lower.Inflate(-1, 0); lower.Y = 8; lower.Height = 8; using (LinearGradientBrush brush = new LinearGradientBrush( lower, arrowColors[index, 6], arrowColors[index, 7], LinearGradientMode.Vertical)) { g.FillRectangle(brush, lower); } lower.Inflate(-1, 0); using (LinearGradientBrush brush = new LinearGradientBrush( lower, arrowColors[index, 4], arrowColors[index, 5], LinearGradientMode.Vertical)) { g.FillRectangle(brush, lower); } } //-- Use code below to draw arrow images from a resource file. //using (Image arrowIcon = Properties.ScrollBarResources.ScrollBarArrowDown) //{ // if (state == ScrollBarArrowButtonState.DownDisabled // || state == ScrollBarArrowButtonState.UpDisabled) // { // System.Windows.Forms.ControlPaint.DrawImageDisabled( // g, // arrowIcon, // 3, // 6, // Color.Transparent); // } // else // { // g.DrawImage(arrowIcon, 3, 6); // } //} } return(bitmap); }
/// <summary> /// Raises the MouseUp event. /// </summary> /// <param name="e">A <see cref="MouseEventArgs"/> that contains the event data.</param> protected override void OnMouseUp(MouseEventArgs e) { base.OnMouseUp(e); if (e.Button == MouseButtons.Left) { this.ContextMenuStrip = this.contextMenu; if (this.thumbClicked) { this.thumbClicked = false; this.thumbState = ScrollBarState.Normal; this.OnScroll(new ScrollEventArgs(ScrollEventType.EndScroll, -1, this.value, this.scrollOrientation)); } else if (this.topArrowClicked) { this.topArrowClicked = false; this.topButtonState = ScrollBarArrowButtonState.UpNormal; this.StopTimer(); } else if (this.bottomArrowClicked) { this.bottomArrowClicked = false; this.bottomButtonState = ScrollBarArrowButtonState.DownNormal; this.StopTimer(); } else if (this.topBarClicked) { this.topBarClicked = false; this.StopTimer(); } else if (this.bottomBarClicked) { this.bottomBarClicked = false; this.StopTimer(); } Invalidate(); } }
/// <summary> /// Raises the MouseEnter event. /// </summary> /// <param name="e">A <see cref="EventArgs"/> that contains the event data.</param> protected override void OnMouseEnter(EventArgs e) { base.OnMouseEnter(e); this.bottomButtonState = ScrollBarArrowButtonState.DownActive; this.topButtonState = ScrollBarArrowButtonState.UpActive; this.thumbState = ScrollBarState.Active; Invalidate(); }
public void DrawArrowButton(Graphics g, Rectangle rect, ScrollBarArrowButtonState state, bool arrowUp, ScrollBarOrientation orientation) { switch (state) { case ScrollBarArrowButtonState.UpDisabled: case ScrollBarArrowButtonState.UpNormal: case ScrollBarArrowButtonState.UpActive: case ScrollBarArrowButtonState.DownDisabled: case ScrollBarArrowButtonState.DownNormal: case ScrollBarArrowButtonState.DownActive: g.FillRectangle(ArrowButtonsBrush, rect); break; case ScrollBarArrowButtonState.UpPressed: case ScrollBarArrowButtonState.DownPressed: g.FillRectangle(ArrowButtonsPressedBrush, rect); break; default: g.FillRectangle(ArrowButtonsHoverBrush, rect); break; } }
/// <summary> /// Raises the MouseDown event. /// </summary> /// <param name="e">A <see cref="MouseEventArgs"/> that contains the event data.</param> protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); //this.Focus(); if (e.Button == MouseButtons.Left) { // prevents showing the context menu if pressing the right mouse // button while holding the left this.ContextMenuStrip = null; Point mouseLocation = e.Location; if (this.thumbRectangle.Contains(mouseLocation)) { this.thumbClicked = true; this.thumbPosition = this.orientation == ScrollBarOrientation.Vertical ? mouseLocation.Y - this.thumbRectangle.Y : mouseLocation.X - this.thumbRectangle.X; this.thumbState = ScrollBarState.Pressed; Invalidate(this.thumbRectangle); } else if (this.topArrowRectangle.Contains(mouseLocation)) { this.topArrowClicked = true; this.topButtonState = ScrollBarArrowButtonState.UpPressed; this.Invalidate(this.topArrowRectangle); this.ProgressThumb(true); } else if (this.bottomArrowRectangle.Contains(mouseLocation)) { this.bottomArrowClicked = true; this.bottomButtonState = ScrollBarArrowButtonState.DownPressed; this.Invalidate(this.bottomArrowRectangle); this.ProgressThumb(true); } else { this.trackPosition = this.orientation == ScrollBarOrientation.Vertical ? mouseLocation.Y : mouseLocation.X; if (this.trackPosition < (this.orientation == ScrollBarOrientation.Vertical ? this.thumbRectangle.Y : this.thumbRectangle.X)) { this.topBarClicked = true; } else { this.bottomBarClicked = true; } this.ProgressThumb(true); } } else if (e.Button == MouseButtons.Right) { this.trackPosition = this.orientation == ScrollBarOrientation.Vertical ? e.Y : e.X; } }
/// <summary> /// Draws an arrow button. /// </summary> /// <param name="g">The <see cref="Graphics"/> used to paint.</param> /// <param name="rect">The rectangle in which to paint.</param> /// <param name="state">The <see cref="ScrollBarArrowButtonState"/> of the arrow button.</param> /// <param name="arrowUp">true for an up arrow, false otherwise.</param> /// <param name="orientation">The <see cref="ScrollBarOrientation"/>.</param> private void DrawArrowButton(Graphics g, Rectangle rect, ScrollBarArrowButtonState state, bool arrowUp, ScrollBarOrientation orientation) { if (g == null) throw new ArgumentNullException("g"); if (rect.IsEmpty || g.IsVisibleClipEmpty || !g.VisibleClipBounds.IntersectsWith(rect)) return; Color color; switch (state) { case ScrollBarArrowButtonState.UpHot: case ScrollBarArrowButtonState.DownHot: color = arrowColorHot; break; case ScrollBarArrowButtonState.UpPressed: case ScrollBarArrowButtonState.DownPressed: color = arrowColorPressed; break; default: color = arrowColor; break; } switch (orientation) { case ScrollBarOrientation.Vertical: DrawArrowButtonVertical(g, rect, color, arrowUp); break; default: DrawArrowButtonHorizontal(g, rect, color, arrowUp); break; } }
public static void DrawArrowButton(Graphics g, Rectangle bounds, ScrollBarArrowButtonState state) { throw null; }
/// <summary> /// Draws the arrow down button for the scrollbar. /// </summary> /// <param name="state">The button state.</param> /// <returns>The arrow down button as <see cref="Image"/>.</returns> private static Image GetArrowDownButtonImage( ScrollBarArrowButtonState state) { Rectangle rect = new Rectangle(0, 0, 15, 17); Bitmap bitmap = new Bitmap(15, 17, PixelFormat.Format32bppArgb); bitmap.SetResolution(72f, 72f); using (Graphics g = Graphics.FromImage(bitmap)) { g.SmoothingMode = SmoothingMode.None; g.InterpolationMode = InterpolationMode.Low; int index = -1; switch (state) { case ScrollBarArrowButtonState.UpHot: case ScrollBarArrowButtonState.DownHot: { index = 1; break; } case ScrollBarArrowButtonState.UpActive: case ScrollBarArrowButtonState.DownActive: { index = 0; break; } case ScrollBarArrowButtonState.UpPressed: case ScrollBarArrowButtonState.DownPressed: { index = 2; break; } } if (index != -1) { using (Pen p1 = new Pen(arrowBorderColors[0]), p2 = new Pen(arrowBorderColors[1])) { g.DrawLine(p1, rect.X, rect.Y, rect.Right - 1, rect.Y); g.DrawLine(p2, rect.X, rect.Bottom - 1, rect.Right - 1, rect.Bottom - 1); } rect.Inflate(0, -1); using (LinearGradientBrush brush = new LinearGradientBrush( rect, arrowBorderColors[2], arrowBorderColors[1], LinearGradientMode.Vertical)) { ColorBlend blend = new ColorBlend(3) { Positions = new[] { 0f, .5f, 1f }, Colors = new[] { arrowBorderColors[2], arrowBorderColors[3], arrowBorderColors[0] } }; brush.InterpolationColors = blend; using (Pen p = new Pen(brush)) { g.DrawLine(p, rect.X, rect.Y, rect.X, rect.Bottom - 1); g.DrawLine(p, rect.Right - 1, rect.Y, rect.Right - 1, rect.Bottom - 1); } } rect.Inflate(0, 1); Rectangle upper = rect; upper.Inflate(-1, 0); upper.Y++; upper.Height = 7; using (LinearGradientBrush brush = new LinearGradientBrush( upper, arrowColors[index, 2], arrowColors[index, 3], LinearGradientMode.Vertical)) { g.FillRectangle(brush, upper); } upper.Inflate(-1, 0); upper.Height = 6; using (LinearGradientBrush brush = new LinearGradientBrush( upper, arrowColors[index, 0], arrowColors[index, 1], LinearGradientMode.Vertical)) { g.FillRectangle(brush, upper); } Rectangle lower = rect; lower.Inflate(-1, 0); lower.Y = 8; lower.Height = 8; using (LinearGradientBrush brush = new LinearGradientBrush( lower, arrowColors[index, 6], arrowColors[index, 7], LinearGradientMode.Vertical)) { g.FillRectangle(brush, lower); } lower.Inflate(-1, 0); using (LinearGradientBrush brush = new LinearGradientBrush( lower, arrowColors[index, 4], arrowColors[index, 5], LinearGradientMode.Vertical)) { g.FillRectangle(brush, lower); } } using (Image arrowIcon = GUI.Properties.Resources.ScrollBarArrowDown) { if (state == ScrollBarArrowButtonState.DownDisabled || state == ScrollBarArrowButtonState.UpDisabled) { System.Windows.Forms.ControlPaint.DrawImageDisabled( g, arrowIcon, 3, 6, Color.Transparent); } else { g.DrawImage(arrowIcon, 3, 6); } } } return bitmap; }
/// <summary> /// Raises the MouseMove event. /// </summary> /// <param name="e">A <see cref="MouseEventArgs"/> that contains the event data.</param> protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); // moving and holding the left mouse button if (e.Button == MouseButtons.Left) { // Update the thumb position, if the new location is within the bounds. if (this.thumbClicked) { int oldScrollValue = this.value; this.topButtonState = ScrollBarArrowButtonState.UpActive; this.bottomButtonState = ScrollBarArrowButtonState.DownActive; int pos = this.orientation == ScrollBarOrientation.Vertical ? e.Location.Y : e.Location.X; // The thumb is all the way to the top if (pos <= (this.thumbTopLimit + this.thumbPosition)) { this.ChangeThumbPosition(this.thumbTopLimit); this.value = this.minimum; } else if (pos >= (this.thumbBottomLimitTop + this.thumbPosition)) { // The thumb is all the way to the bottom this.ChangeThumbPosition(this.thumbBottomLimitTop); this.value = this.maximum; } else { // The thumb is between the ends of the track. this.ChangeThumbPosition(pos - this.thumbPosition); int pixelRange, thumbPos, arrowSize; // calculate the value - first some helper variables // dependent on the current orientation if (this.orientation == ScrollBarOrientation.Vertical) { pixelRange = this.Height - (2 * this.arrowHeight) - this.thumbHeight; thumbPos = this.thumbRectangle.Y; arrowSize = this.arrowHeight; } else { pixelRange = this.Width - (2 * this.arrowWidth) - this.thumbWidth; thumbPos = this.thumbRectangle.X; arrowSize = this.arrowWidth; } float perc = 0f; if (pixelRange != 0) { // percent of the new position perc = (float)(thumbPos - arrowSize) / (float)pixelRange; } // the new value is somewhere between max and min, starting // at min position this.value = Convert.ToInt32((perc * (this.maximum - this.minimum)) + this.minimum); } // raise scroll event if new value different if (oldScrollValue != this.value) { this.OnScroll(new ScrollEventArgs(ScrollEventType.ThumbTrack, oldScrollValue, this.value, this.scrollOrientation)); this.Refresh(); } } } else if (!this.ClientRectangle.Contains(e.Location)) { this.ResetScrollStatus(); } else if (e.Button == MouseButtons.None) // only moving the mouse { if (this.topArrowRectangle.Contains(e.Location)) { this.topButtonState = ScrollBarArrowButtonState.UpHot; this.Invalidate(this.topArrowRectangle); } else if (this.bottomArrowRectangle.Contains(e.Location)) { this.bottomButtonState = ScrollBarArrowButtonState.DownHot; Invalidate(this.bottomArrowRectangle); } else if (this.thumbRectangle.Contains(e.Location)) { this.thumbState = ScrollBarState.Hot; this.Invalidate(this.thumbRectangle); } else if (this.ClientRectangle.Contains(e.Location)) { this.topButtonState = ScrollBarArrowButtonState.UpActive; this.bottomButtonState = ScrollBarArrowButtonState.DownActive; this.thumbState = ScrollBarState.Active; Invalidate(); } } }
/// <summary> /// Draws the arrow down button for the scrollbar. /// </summary> /// <param name="state">The button state.</param> /// <returns>The arrow down button as <see cref="Image"/>.</returns> private static Image GetArrowDownButtonImage( ScrollBarArrowButtonState state) { Rectangle rect = new Rectangle(0, 0, 15, 17); Bitmap bitmap = new Bitmap(15, 17, PixelFormat.Format32bppArgb); bitmap.SetResolution(72f, 72f); using (Graphics g = Graphics.FromImage(bitmap)) { g.SmoothingMode = SmoothingMode.None; g.InterpolationMode = InterpolationMode.Low; int index = -1; switch (state) { case ScrollBarArrowButtonState.UPHOT: case ScrollBarArrowButtonState.DOWNHOT: { index = 1; break; } case ScrollBarArrowButtonState.UPACTIVE: case ScrollBarArrowButtonState.DOWNACTIVE: { index = 0; break; } case ScrollBarArrowButtonState.UPPRESSED: case ScrollBarArrowButtonState.DOWNPRESSED: { index = 2; break; } } if (index != -1) { using (Pen p1 = new Pen(arrowBorderColours[0]), p2 = new Pen(arrowBorderColours[1])) { g.DrawLine(p1, rect.X, rect.Y, rect.Right - 1, rect.Y); g.DrawLine(p2, rect.X, rect.Bottom - 1, rect.Right - 1, rect.Bottom - 1); } rect.Inflate(0, -1); using (LinearGradientBrush brush = new LinearGradientBrush( rect, arrowBorderColours[2], arrowBorderColours[1], LinearGradientMode.Vertical)) { ColorBlend blend = new ColorBlend(3) { Positions = new[] { 0f, .5f, 1f }, Colors = new[] { arrowBorderColours[2], arrowBorderColours[3], arrowBorderColours[0] } }; brush.InterpolationColors = blend; using (Pen p = new Pen(brush)) { g.DrawLine(p, rect.X, rect.Y, rect.X, rect.Bottom - 1); g.DrawLine(p, rect.Right - 1, rect.Y, rect.Right - 1, rect.Bottom - 1); } } rect.Inflate(0, 1); Rectangle upper = rect; upper.Inflate(-1, 0); upper.Y++; upper.Height = 7; using (LinearGradientBrush brush = new LinearGradientBrush( upper, arrowColours[index, 2], arrowColours[index, 3], LinearGradientMode.Vertical)) { g.FillRectangle(brush, upper); } upper.Inflate(-1, 0); upper.Height = 6; using (LinearGradientBrush brush = new LinearGradientBrush( upper, arrowColours[index, 0], arrowColours[index, 1], LinearGradientMode.Vertical)) { g.FillRectangle(brush, upper); } Rectangle lower = rect; lower.Inflate(-1, 0); lower.Y = 8; lower.Height = 8; using (LinearGradientBrush brush = new LinearGradientBrush( lower, arrowColours[index, 6], arrowColours[index, 7], LinearGradientMode.Vertical)) { g.FillRectangle(brush, lower); } lower.Inflate(-1, 0); using (LinearGradientBrush brush = new LinearGradientBrush( lower, arrowColours[index, 4], arrowColours[index, 5], LinearGradientMode.Vertical)) { g.FillRectangle(brush, lower); } } using (Image arrowIcon = (Image)GetScrollBarArrowDownBitmap().Clone()) { if (state == ScrollBarArrowButtonState.DOWNDISABLED || state == ScrollBarArrowButtonState.UPDISABLED) { System.Windows.Forms.ControlPaint.DrawImageDisabled( g, arrowIcon, 3, 6, Color.Transparent); } else { g.DrawImage(arrowIcon, 3, 6); } } } return(bitmap); }
/// <summary> /// Raises the <see cref="System.Windows.Forms.Control.EnabledChanged"/> event. /// </summary> /// <param name="e">An <see cref="EventArgs"/> that contains the event data.</param> protected override void OnEnabledChanged(EventArgs e) { base.OnEnabledChanged(e); if (this.Enabled) { this.thumbState = ScrollBarState.Normal; this.topButtonState = ScrollBarArrowButtonState.UpNormal; this.bottomButtonState = ScrollBarArrowButtonState.DownNormal; } else { this.thumbState = ScrollBarState.Disabled; this.topButtonState = ScrollBarArrowButtonState.UpDisabled; this.bottomButtonState = ScrollBarArrowButtonState.DownDisabled; } this.Refresh(); }
public static void DrawArrowButton (Graphics g, Rectangle bounds, ScrollBarArrowButtonState state) { if (!IsSupported) throw new InvalidOperationException (); VisualStyleRenderer vsr; switch (state) { case ScrollBarArrowButtonState.DownDisabled: vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.DownDisabled); break; case ScrollBarArrowButtonState.DownHot: vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.DownHot); break; case ScrollBarArrowButtonState.DownNormal: default: vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.DownNormal); break; case ScrollBarArrowButtonState.DownPressed: vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.DownPressed); break; case ScrollBarArrowButtonState.LeftDisabled: vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.LeftDisabled); break; case ScrollBarArrowButtonState.LeftHot: vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.LeftHot); break; case ScrollBarArrowButtonState.LeftNormal: vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.LeftNormal); break; case ScrollBarArrowButtonState.LeftPressed: vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.LeftPressed); break; case ScrollBarArrowButtonState.RightDisabled: vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.RightDisabled); break; case ScrollBarArrowButtonState.RightHot: vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.RightHot); break; case ScrollBarArrowButtonState.RightNormal: vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.RightNormal); break; case ScrollBarArrowButtonState.RightPressed: vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.RightPressed); break; case ScrollBarArrowButtonState.UpDisabled: vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.UpDisabled); break; case ScrollBarArrowButtonState.UpHot: vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.UpHot); break; case ScrollBarArrowButtonState.UpNormal: vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.UpNormal); break; case ScrollBarArrowButtonState.UpPressed: vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ArrowButton.UpPressed); break; } vsr.DrawBackground(g, bounds); }
private static void DrawModernArrow(Graphics g, Rectangle r, ScrollBarArrowButtonState state) { if (r.Width < 17 || r.Height < 18) { // ScrollBarRenderer does a terrible job at small sizes. So the image is drawn onto a larger // rectangle, and then the middle of that image is cropped out. Note: > 20, the a larger arrow // is used. using (Bitmap bmp = new Bitmap(Math.Max(20, r.Width), Math.Max(20, r.Height))) { using (var g2 = Graphics.FromImage(bmp)) { ScrollBarRenderer.DrawArrowButton(g2, new Rectangle(0, 0, bmp.Width, bmp.Height), state); using (Bitmap bmp2 = bmp.Clone(new Rectangle((bmp.Width - r.Width) / 2, (bmp.Height - r.Height) / 2, r.Width, r.Height), bmp.PixelFormat)) { g.DrawImageUnscaled(bmp2, 0, 0); } } } } else ScrollBarRenderer.DrawArrowButton(g, r, state); }