public static void DrawVerticalThumb(Graphics g, Rectangle bounds, ScrollBarState state) { if (!IsSupported) { throw new InvalidOperationException(); } VisualStyleRenderer vsr; switch (state) { case ScrollBarState.Disabled: vsr = new VisualStyleRenderer(VisualStyleElement.ScrollBar.ThumbButtonVertical.Disabled); break; case ScrollBarState.Hot: vsr = new VisualStyleRenderer(VisualStyleElement.ScrollBar.ThumbButtonVertical.Hot); break; case ScrollBarState.Normal: default: vsr = new VisualStyleRenderer(VisualStyleElement.ScrollBar.ThumbButtonVertical.Normal); break; case ScrollBarState.Pressed: vsr = new VisualStyleRenderer(VisualStyleElement.ScrollBar.ThumbButtonVertical.Pressed); break; } vsr.DrawBackground(g, bounds); }
protected override void OnPaint(PaintEventArgs e) { if (VisualStyleInformation.IsEnabledByUser) { ScrollBarState ss = ScrollBarState.Normal; if (!Enabled) { ss = ScrollBarState.Disabled; } else if (IsMouseDown) { ss = ScrollBarState.Pressed; } else if (IsMouseHover) { ss = ScrollBarState.Hot; } ScrollBarRenderer.DrawHorizontalThumb(e.Graphics, ClientRectangle, ss); } else { base.OnPaint(e); } Image image = Properties.Resources.navigation_button; e.Graphics.DrawImage(image, new Rectangle((ClientSize.Width - image.Width) / 2, (ClientSize.Height - image.Height) / 2, image.Width, image.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel); }
public override void OnMouseMoved(BasicMouseEventArgs e) { ScrollBarState newState = ScrollBarState.Neutral; if (e.Y < GraphUtil.scrollBarWidth - 1) { newState = ScrollBarState.HighlightFirstBox; } else if (e.Y > e.Height - GraphUtil.scrollBarWidth) { newState = ScrollBarState.HighlightSecondBox; } else if (HasBar) { int s = CalcBarStart(e.Height); int l = CalcBarSize(e.Height); if (e.Y >= s && e.Y <= s + l) { newState = ScrollBarState.HighlightBar; } } if (newState != state) { state = newState; Invalidate(); } }
/// <summary> /// Draws the thumb. /// </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="ScrollBarState"/> of the thumb.</param> /// <param name="orientation">The <see cref="ScrollBarOrientation"/>.</param> private void DrawThumb(Graphics g, Rectangle rect, ScrollBarState state, ScrollBarOrientation orientation) { if (g == null) throw new ArgumentNullException("g"); if (rect.IsEmpty || g.IsVisibleClipEmpty || !g.VisibleClipBounds.IntersectsWith(rect) || state == ScrollBarState.Disabled) return; Color color; switch (state) { case ScrollBarState.Hot: color = foreColorHot; break; case ScrollBarState.Pressed: color = foreColorPressed; break; default: color = foreColor; break; } switch (orientation) { case ScrollBarOrientation.Vertical: DrawThumbVertical(g, rect, color); break; default: DrawThumbHorizontal(g, rect, color); break; } }
void IScrollBar.ChangeValueBasedByState(ScrollBarState state) { int newValue = Value; ScrollEventType scrollType = ScrollEventType.EndScroll; switch (state) { case ScrollBarState.IncButtonPressed: newValue -= SmallChange; scrollType = ScrollEventType.SmallIncrement; break; case ScrollBarState.DecButtonPressed: newValue += SmallChange; scrollType = ScrollEventType.SmallDecrement; break; case ScrollBarState.IncAreaPressed: newValue -= LargeChange; scrollType = ScrollEventType.LargeIncrement; break; case ScrollBarState.DecAreaPressed: newValue += LargeChange; scrollType = ScrollEventType.LargeDecrement; break; } if (scrollType != ScrollEventType.EndScroll) { SetScrollBarValueCore(scrollType, newValue); } }
/// <summary> /// Draws the channel ( or track ). /// </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 scrollbar state.</param> /// <param name="orientation">The <see cref="ScrollBarOrientation"/>.</param> public static void DrawTrack( Graphics g, Rectangle rect, ScrollBarState state, ScrollBarOrientation orientation) { if (g == null) { throw new ArgumentNullException("g"); } if (rect.Width <= 0 || rect.Height <= 0 || state != ScrollBarState.PRESSED || g.IsVisibleClipEmpty || !g.VisibleClipBounds.IntersectsWith(rect)) { return; } if (orientation == ScrollBarOrientation.VERTICAL) { DrawTrackVertical(g, rect); } else { DrawTrackHorizontal(g, rect); } }
/// <summary> /// Draws the thumb. /// </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="ScrollBarState"/> of the thumb.</param> /// <param name="orientation">The <see cref="ScrollBarOrientation"/>.</param> public static void DrawThumb( Graphics g, Rectangle rect, ScrollBarState state, ScrollBarOrientation orientation) { if (g == null) { throw new ArgumentNullException("g"); } if (rect.IsEmpty || g.IsVisibleClipEmpty || !g.VisibleClipBounds.IntersectsWith(rect) || state == ScrollBarState.DISABLED) { return; } if (orientation == ScrollBarOrientation.VERTICAL) { DrawThumbVertical(g, rect, state); } else { DrawThumbHorizontal(g, rect, state); } }
protected internal override void OnMouseMoved(BasicMouseEventArgs e) { ScrollBarState newState = ScrollBarState.Neutral; if (e.X < CompoundScrollableControl.scrollBarWidth - 1) { newState = ScrollBarState.HighlightFirstBox; } else if (e.X > e.Width - CompoundScrollableControl.scrollBarWidth) { newState = ScrollBarState.HighlightSecondBox; } else if (HasBar) { int s = CalcBarStart(e.Width); int l = CalcBarSize(e.Width); if (e.X >= s && e.X <= s + l) { newState = ScrollBarState.HighlightBar; } } if (newState != state) { state = newState; Invalidate(); } }
void SetColor() { if (state == ScrollBarState.Showing) { imageColor.a = 0.5f; state = ScrollBarState.Show; } else if (state == ScrollBarState.Hiding) { imageColor.a -= Time.deltaTime; if (imageColor.a < 0) { imageColor.a = 0; state = ScrollBarState.Hide; } } else if (state == ScrollBarState.Show) { imageColor.a = 0.5f; } else if (state == ScrollBarState.Hide) { imageColor.a = 0; } image.color = imageColor; }
protected override void OnMouseEnter(EventArgs e) { base.OnMouseEnter(e); bottomButtonState = ScrollBarState.Active; topButtonState = ScrollBarState.Active; thumbState = ScrollBarState.Active; Invalidate(); }
protected internal override void OnMouseLeave(EventArgs e) { if (state == ScrollBarState.PressBar) { return; } state = ScrollBarState.Neutral; Invalidate(); }
//</Snippet2> // Handle a mouse click in the scroll bar. protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); if (!ScrollBarRenderer.IsSupported) { return; } // When the thumb is clicked, update the distance from the left // edge of the thumb to the cursor tip. if (thumbRectangle.Contains(e.Location)) { thumbClicked = true; thumbPosition = e.Location.X - thumbRectangle.X; thumbState = ScrollBarState.Pressed; } // When the left arrow is clicked, start the timer to scroll // while the arrow is held down. else if (leftArrowRectangle.Contains(e.Location)) { leftArrowClicked = true; leftButtonState = ScrollBarArrowButtonState.LeftPressed; progressTimer.Start(); } // When the right arrow is clicked, start the timer to scroll // while the arrow is held down. else if (rightArrowRectangle.Contains(e.Location)) { rightArrowClicked = true; rightButtonState = ScrollBarArrowButtonState.RightPressed; progressTimer.Start(); } // When the scroll bar is clicked, start the timer to move the // thumb while the mouse is held down. else { trackPosition = e.Location.X; if (e.Location.X < this.thumbRectangle.X) { leftBarClicked = true; } else { rightBarClicked = true; } progressTimer.Start(); } Invalidate(); }
public static Size GetThumbGripSize(Graphics g, ScrollBarState state) { if (!IsSupported) { throw new InvalidOperationException(); } VisualStyleRenderer vsr = new VisualStyleRenderer(VisualStyleElement.ScrollBar.GripperVertical.Normal); return(vsr.GetPartSize(g, ThemeSizeType.Draw)); }
public static Size GetSizeBoxSize(Graphics g, ScrollBarState state) { if (!IsSupported) { throw new InvalidOperationException(); } VisualStyleRenderer vsr = new VisualStyleRenderer(VisualStyleElement.ScrollBar.SizeBox.LeftAlign); return(vsr.GetPartSize(g, ThemeSizeType.Draw)); }
// Draw the track. protected override void OnMouseUp(MouseEventArgs e) { base.OnMouseUp(e); if (!ScrollBarRenderer.IsSupported) { return; } // Update the thumb position, if the new location is within // the bounds. if (thumbClicked) { thumbClicked = false; thumbState = ScrollBarState.Normal; if (e.Location.X > (thumbLeftLimit + thumbPosition) && e.Location.X < (thumbRightLimitLeft + thumbPosition)) { thumbRectangle.X = e.Location.X - thumbPosition; thumbClicked = false; } } // If one of the four thumb movement areas was clicked, // stop the timer. else if (leftArrowClicked) { leftArrowClicked = false; leftButtonState = ScrollBarArrowButtonState.LeftNormal; progressTimer.Stop(); } else if (rightArrowClicked) { rightArrowClicked = false; rightButtonState = ScrollBarArrowButtonState.RightNormal; progressTimer.Stop(); } else if (leftBarClicked) { leftBarClicked = false; progressTimer.Stop(); } else if (rightBarClicked) { rightBarClicked = false; progressTimer.Stop(); } Invalidate(); }
public static void DrawVerticalThumbGrip(Graphics g, Rectangle bounds, ScrollBarState state) { if (!IsSupported) { throw new InvalidOperationException(); } VisualStyleRenderer vsr = new VisualStyleRenderer(VisualStyleElement.ScrollBar.GripperVertical.Normal);; vsr.DrawBackground(g, bounds); }
public void HideScrollBar() { if (!hideBarWhenNotMoving) { return; } if (state == ScrollBarState.Hide) { return; } state = ScrollBarState.Hiding; }
public void ShowScrollBar() { if (!hideBarWhenNotMoving) { return; } if (state == ScrollBarState.Show) { return; } state = ScrollBarState.Showing; }
protected override void OnPaint(PaintEventArgs e) { if (!thumbenable && HideScrollBar && !DesignMode) { return; } if (FlatStyle == FlatStyle.System && ScrollBarRenderer.IsSupported) { ScrollBarArrowButtonState up = (mousepressed == MouseOver.MouseOverUp) ? ScrollBarArrowButtonState.UpPressed : (mouseover == MouseOver.MouseOverUp) ? ScrollBarArrowButtonState.UpHot : ScrollBarArrowButtonState.UpNormal; ScrollBarArrowButtonState down = (mousepressed == MouseOver.MouseOverDown) ? ScrollBarArrowButtonState.DownPressed : (mouseover == MouseOver.MouseOverUp) ? ScrollBarArrowButtonState.DownHot : ScrollBarArrowButtonState.DownNormal; ScrollBarState thumb = (mousepressed == MouseOver.MouseOverThumb) ? ScrollBarState.Pressed : (mouseover == MouseOver.MouseOverThumb) ? ScrollBarState.Hot : ScrollBarState.Normal; ScrollBarState track = ScrollBarState.Normal; if (!Enabled || !thumbenable) { up = ScrollBarArrowButtonState.UpDisabled; down = ScrollBarArrowButtonState.DownDisabled; thumb = ScrollBarState.Disabled; track = ScrollBarState.Disabled; } ScrollBarRenderer.DrawArrowButton(e.Graphics, upbuttonarea, up); ScrollBarRenderer.DrawArrowButton(e.Graphics, downbuttonarea, down); if (Enabled && thumbenable) { Rectangle upper = new Rectangle(sliderarea.X, sliderarea.Y, sliderarea.Width, thumbbuttonarea.Y - sliderarea.Y); Rectangle lower = new Rectangle(sliderarea.X, thumbbuttonarea.Bottom, sliderarea.Width, sliderarea.Bottom - thumbbuttonarea.Bottom); //Console.WriteLine("System " + upper + " l: " + lower); ScrollBarRenderer.DrawUpperVerticalTrack(e.Graphics, upper, track); ScrollBarRenderer.DrawLowerVerticalTrack(e.Graphics, lower, track); ScrollBarRenderer.DrawVerticalThumb(e.Graphics, thumbbuttonarea, thumb); } else { ScrollBarRenderer.DrawUpperVerticalTrack(e.Graphics, sliderarea, ScrollBarState.Disabled); } } else { using (Brush br = new SolidBrush(SliderColor)) e.Graphics.FillRectangle(br, sliderarea); using (Pen pr = new Pen(BorderColor)) e.Graphics.DrawRectangle(pr, borderrect); //System.Diagnostics.Debug.WriteLine("Scroll bar redraw " + Parent.Parent.Name + " " + e.Graphics.ClipBounds +" " + ClientRectangle + " " + sliderarea + " " + upbuttonarea + " " + downbuttonarea + " " + thumbbuttonarea); DrawButton(e.Graphics, upbuttonarea, MouseOver.MouseOverUp); DrawButton(e.Graphics, downbuttonarea, MouseOver.MouseOverDown); DrawButton(e.Graphics, thumbbuttonarea, MouseOver.MouseOverThumb); } }
// Handle a mouse click in the scroll bar. protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); // When the thumb is clicked, update the distance from the left // edge of the thumb to the cursor tip. if (thumbRectangle.Contains(e.Location)) { thumbClicked = true; thumbPosition = e.Location.Y - thumbRectangle.Y; thumbState = ScrollBarState.Pressed; } // When the left arrow is clicked, start the timer to scroll // while the arrow is held down. else if (upArrowRectangle.Contains(e.Location)) { upArrowClicked = true; upButtonState = ScrollBarArrowButtonState.UpPressed; progressTimer.Start(); } // When the right arrow is clicked, start the timer to scroll // while the arrow is held down. else if (downArrowRectangle.Contains(e.Location)) { downArrowClicked = true; downButtonState = ScrollBarArrowButtonState.DownPressed; progressTimer.Start(); } // When the scroll bar is clicked, start the timer to move the // thumb while the mouse is held down. else { trackPosition = e.Location.Y; if (e.Location.Y < this.thumbRectangle.Y) { upBarClicked = true; } else { downBarClicked = true; } progressTimer.Start(); } Invalidate(); }
// Draw the track. protected override void OnMouseUp(MouseEventArgs e) { base.OnMouseUp(e); // Update the thumb position, if the new location is within // the bounds. if (thumbClicked) { thumbClicked = false; thumbState = ScrollBarState.Normal; if (e.Location.Y > (thumbUpLimit + thumbPosition) && e.Location.Y < (thumbDownLimitUp + thumbPosition)) { thumbRectangle.Y = e.Location.Y - thumbPosition; thumbClicked = false; } } // If one of the four thumb movement areas was clicked, // stop the timer. else if (upArrowClicked) { upArrowClicked = false; upButtonState = ScrollBarArrowButtonState.UpNormal; progressTimer.Stop(); } else if (downArrowClicked) { downArrowClicked = false; downButtonState = ScrollBarArrowButtonState.DownNormal; progressTimer.Stop(); } else if (upBarClicked) { upBarClicked = false; progressTimer.Stop(); } else if (downBarClicked) { downBarClicked = false; progressTimer.Stop(); } Invalidate(); }
public static void DrawThumb(Graphics g, Scheme scheme, Rectangle rect, ScrollBarState state, bool isHorizontal) { if (rect.IsEmpty || g.IsVisibleClipEmpty || !g.VisibleClipBounds.IntersectsWith(rect) || state == ScrollBarState.Disabled) { return; } if (state == ScrollBarState.Hot || state == ScrollBarState.Pressed) { g.FillRectangle(scheme.scrollThumbHoverBrush, rect); } else { g.FillRectangle(scheme.scrollThumbBrush, rect); } }
protected internal override void OnMouseIsDown(BasicMouseEventArgs e) { ScrollBarState newState = ScrollBarState.Neutral; if (e.X < CompoundScrollableControl.scrollBarWidth - 1) { newState = ScrollBarState.PressFirstBox; MoveLeft(main.DeltaX); leftThread = new Thread(() => WalkLeft(main.DeltaX)); leftThread.Start(); } else if (e.X > e.Width - CompoundScrollableControl.scrollBarWidth) { newState = ScrollBarState.PressSecondBox; MoveRight(main.DeltaX); rightThread = new Thread(() => WalkRight(main.DeltaX)); rightThread.Start(); } else if (HasBar) { int s = CalcBarStart(e.Width); int l = CalcBarSize(e.Width); if (e.X >= s && e.X <= s + l) { newState = ScrollBarState.PressBar; dragStart = e.X; visibleDragStart = main.VisibleX; } else if (e.X < s) { MoveLeft(main.VisibleWidth); leftThread = new Thread(() => WalkLeft(main.VisibleWidth)); leftThread.Start(); } else { MoveRight(main.VisibleWidth); rightThread = new Thread(() => WalkRight(main.VisibleWidth)); rightThread.Start(); } } if (newState != state) { state = newState; Invalidate(); } }
public override void OnMouseIsDown(BasicMouseEventArgs e) { ScrollBarState newState = ScrollBarState.Neutral; if (e.X < GraphUtil.scrollBarWidth - 1) { newState = ScrollBarState.PressFirstBox; MoveLeft(main.DeltaX()); leftThread = new Thread(() => WalkLeft(main.DeltaX())); leftThread.Start(); } else if (e.X > e.Width - GraphUtil.scrollBarWidth) { newState = ScrollBarState.PressSecondBox; MoveRight(main.DeltaX()); rightThread = new Thread(() => WalkRight(main.DeltaX())); rightThread.Start(); } else if (HasBar) { int s = CalcBarStart(e.Width); int l = CalcBarSize(e.Width); if (e.X >= s && e.X <= s + l) { newState = ScrollBarState.PressBar; dragStart = e.X; visibleDragStart = main.VisibleX; } else if (e.X < s) { MoveLeft((int)(main.VisibleWidth / main.ZoomFactor)); leftThread = new Thread(() => WalkLeft((int)(main.VisibleWidth / main.ZoomFactor))); leftThread.Start(); } else { MoveRight((int)(main.VisibleWidth / main.ZoomFactor)); rightThread = new Thread(() => WalkRight((int)(main.VisibleWidth / main.ZoomFactor))); rightThread.Start(); } } if (newState != state) { state = newState; Invalidate(); } }
protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); if (e.Button == MouseButtons.Left) { if (thumbClicked) { topButtonState = ScrollBarState.Active; bottomButtonState = ScrollBarState.Active; int oldScrollValue = value; value = GetValueByThumb((isVertical ? e.Location.Y : e.Location.X) - thumbMouseOffset); ThumbPosition = GetThumbByValue(); if (oldScrollValue != value) { OnScroll(new ScrollEventArgs(ScrollEventType.ThumbTrack, oldScrollValue, value, scrollOrientation)); Refresh(); } } } else if (!ClientRectangle.Contains(e.Location)) { ResetScrollStatus(); } if (topArrowRectangle.Contains(e.Location)) { topButtonState = ScrollBarState.Hot; Invalidate(topArrowRectangle); } else if (bottomArrowRectangle.Contains(e.Location)) { bottomButtonState = ScrollBarState.Hot; Invalidate(bottomArrowRectangle); } else if (thumbRectangle.Contains(e.Location)) { thumbState = ScrollBarState.Hot; Invalidate(thumbRectangle); } else if (ClientRectangle.Contains(e.Location)) { topButtonState = ScrollBarState.Active; bottomButtonState = ScrollBarState.Active; thumbState = ScrollBarState.Active; Invalidate(); } }
protected override void OnEnabledChanged(EventArgs e) { base.OnEnabledChanged(e); if (Enabled) { thumbState = ScrollBarState.Normal; topButtonState = ScrollBarState.Normal; bottomButtonState = ScrollBarState.Normal; } else { thumbState = ScrollBarState.Disabled; topButtonState = ScrollBarState.Disabled; bottomButtonState = ScrollBarState.Disabled; } Refresh(); }
/// <summary> /// Determines how to draw the 'thumb' button on the scrollbar. /// </summary> /// <returns></returns> private ScrollBarState GetScrollBarThumbState() { ScrollBarState state = ScrollBarState.Normal; if (_scrollBar.Thumb.Contains(PointToClient(Cursor.Position))) { if ((MouseButtons & MouseButtons.Left) == MouseButtons.Left) { state = ScrollBarState.Pressed; } else { state = ScrollBarState.Hot; } } return(state); }
public override void OnMouseIsUp(BasicMouseEventArgs e) { if (upThread != null) { upThread.Abort(); upThread = null; } if (downThread != null) { downThread.Abort(); downThread = null; } const ScrollBarState newState = ScrollBarState.Neutral; OnMouseMoved(e); state = newState; Invalidate(); }
protected internal override void OnMouseIsUp(BasicMouseEventArgs e) { if (leftThread != null) { leftThread.Abort(); leftThread = null; } if (rightThread != null) { rightThread.Abort(); rightThread = null; } const ScrollBarState newState = ScrollBarState.Neutral; OnMouseMoved(e); state = newState; Invalidate(); }
/// <summary> /// Draws the thumb. /// </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="ScrollBarState"/> of the thumb.</param> /// <param name="orientation">The <see cref="ScrollBarOrientation"/>.</param> private void DrawThumb(Graphics g, Rectangle rect, ScrollBarState state, ScrollBarOrientation orientation) { if (g == null) { throw new ArgumentNullException("g"); } if (rect.IsEmpty || g.IsVisibleClipEmpty || !g.VisibleClipBounds.IntersectsWith(rect) || state == ScrollBarState.Disabled) { return; } if (orientation == ScrollBarOrientation.Vertical) { DrawThumbVertical(g, rect, state); } else { DrawThumbHorizontal(g, rect, state); } }
private void ResetScrollStatus() { Point pos = PointToClient(Cursor.Position); if (ClientRectangle.Contains(pos)) { bottomButtonState = ScrollBarState.Active; topButtonState = ScrollBarState.Active; } else { bottomButtonState = ScrollBarState.Normal; topButtonState = ScrollBarState.Normal; } thumbState = thumbRectangle.Contains(pos) ? ScrollBarState.Hot : ScrollBarState.Normal; bottomArrowClicked = bottomBarClicked = topArrowClicked = topBarClicked = false; StopTimer(); Refresh(); }
public void DrawThumb(Graphics g, Rectangle rect, ScrollBarState state, ScrollBarOrientation orientation) { switch (state) { case ScrollBarState.Disabled: case ScrollBarState.Normal: case ScrollBarState.Active: g.FillRectangle(ThumbBrush, rect); break; case ScrollBarState.Pressed: g.FillRectangle(ThumbPressedBrush, rect); break; default: g.FillRectangle(ThumbHoverBrush, rect); break; } }
/// <summary> /// Draws the thumb. /// </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="ScrollBarState"/> of the thumb.</param> private void DrawThumbHorizontal(Graphics g, Rectangle rect, ScrollBarState state) { Color color = foreColor; switch (state) { case ScrollBarState.Pressed: { color = foreColorActive; break; } } var innerRect = new Rectangle(rect.Left, rect.Top + ScaleHelper.Scale(2), rect.Width, rect.Height - ScaleHelper.Scale(4)); using (Brush brush = new SolidBrush(color)) { g.FillRectangle(brush, innerRect); } }
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] // Using Graphics instead of IDeviceContext intentionally public static Size GetThumbGripSize(Graphics g, ScrollBarState state) { InitializeRenderer(VisualStyleElement.ScrollBar.GripperHorizontal.Normal, (int)state); return visualStyleRenderer.GetPartSize(g, ThemeSizeType.True); }
public override void OnMouseIsUp(BasicMouseEventArgs e) { if (upThread != null){ upThread.Abort(); upThread = null; } if (downThread != null){ downThread.Abort(); downThread = null; } const ScrollBarState newState = ScrollBarState.Neutral; OnMouseMoved(e); state = newState; Invalidate(); }
/// <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(); }
public static Size GetThumbGripSize (Graphics g, ScrollBarState state) { if (!IsSupported) throw new InvalidOperationException (); VisualStyleRenderer vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.GripperVertical.Normal); return vsr.GetPartSize (g, ThemeSizeType.Draw); }
public static void DrawVerticalThumbGrip (Graphics g, Rectangle bounds, ScrollBarState state) { if (!IsSupported) throw new InvalidOperationException (); VisualStyleRenderer vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.GripperVertical.Normal); ; vsr.DrawBackground (g, bounds); }
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] // Using Graphics instead of IDeviceContext intentionally public static Size GetSizeBoxSize(Graphics g, ScrollBarState state) { InitializeRenderer(VisualStyleElement.ScrollBar.SizeBox.LeftAlign, (int)state); return visualStyleRenderer.GetPartSize(g, ThemeSizeType.True); }
public override void OnMouseIsDown(BasicMouseEventArgs e) { ScrollBarState newState = ScrollBarState.Neutral; if (e.X < GraphUtil.scrollBarWidth - 1){ newState = ScrollBarState.PressFirstBox; MoveLeft(main.DeltaX()); leftThread = new Thread(() => WalkLeft(main.DeltaX())); leftThread.Start(); } else if (e.X > e.Width - GraphUtil.scrollBarWidth){ newState = ScrollBarState.PressSecondBox; MoveRight(main.DeltaX()); rightThread = new Thread(() => WalkRight(main.DeltaX())); rightThread.Start(); } else if (HasBar){ int s = CalcBarStart(e.Width); int l = CalcBarSize(e.Width); if (e.X >= s && e.X <= s + l){ newState = ScrollBarState.PressBar; dragStart = e.X; visibleDragStart = main.VisibleX; } else if (e.X < s){ MoveLeft((int) (main.VisibleWidth / main.ZoomFactor)); leftThread = new Thread(() => WalkLeft((int) (main.VisibleWidth / main.ZoomFactor))); leftThread.Start(); } else{ MoveRight((int) (main.VisibleWidth / main.ZoomFactor)); rightThread = new Thread(() => WalkRight((int) (main.VisibleWidth / main.ZoomFactor))); rightThread.Start(); } } if (newState != state){ state = newState; Invalidate(); } }
/// <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 the thumb. /// </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="ScrollBarState"/> of the thumb.</param> private static void DrawThumbVertical( Graphics g, Rectangle rect, ScrollBarState state) { int index = 0; switch (state) { case ScrollBarState.Hot: { index = 1; break; } case ScrollBarState.Pressed: { index = 2; break; } } Rectangle innerRect = rect; innerRect.Inflate(-1, -1); Rectangle r = innerRect; r.Width = 8; r.Height++; // draw left gradient using (LinearGradientBrush brush = new LinearGradientBrush( r, thumbColors[index, 1], thumbColors[index, 2], LinearGradientMode.Horizontal)) { g.FillRectangle(brush, r); } r.X = r.Right; // draw right gradient if (index == 0) { using (LinearGradientBrush brush = new LinearGradientBrush( r, thumbColors[index, 4], thumbColors[index, 5], LinearGradientMode.Horizontal)) { brush.InterpolationColors = new ColorBlend(3) { Colors = new[] { thumbColors[index, 4], thumbColors[index, 6], thumbColors[index, 5] }, Positions = new[] { 0f, .5f, 1f } }; g.FillRectangle(brush, r); } } else { using (LinearGradientBrush brush = new LinearGradientBrush( r, thumbColors[index, 4], thumbColors[index, 5], LinearGradientMode.Horizontal)) { g.FillRectangle(brush, r); } // draw left line using (Pen p = new Pen(thumbColors[index, 7])) { g.DrawLine(p, innerRect.X, innerRect.Y, innerRect.X, innerRect.Bottom); } } // draw right line using (Pen p = new Pen(thumbColors[index, 3])) { g.DrawLine(p, innerRect.Right, innerRect.Y, innerRect.Right, innerRect.Bottom); } g.SmoothingMode = SmoothingMode.AntiAlias; // draw border using (Pen p = new Pen(thumbColors[index, 0])) { using (GraphicsPath path = CreateRoundPath(rect, 2f, 2f)) { g.DrawPath(p, path); } } g.SmoothingMode = SmoothingMode.None; }
/// <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 override void OnMouseMoved(BasicMouseEventArgs e) { ScrollBarState newState = ScrollBarState.Neutral; if (e.Y < GraphUtil.scrollBarWidth - 1){ newState = ScrollBarState.HighlightFirstBox; } else if (e.Y > e.Height - GraphUtil.scrollBarWidth){ newState = ScrollBarState.HighlightSecondBox; } else if (HasBar){ int s = CalcBarStart(e.Height); int l = CalcBarSize(e.Height); if (e.Y >= s && e.Y <= s + l){ newState = ScrollBarState.HighlightBar; } } if (newState != state){ state = newState; Invalidate(); } }
/// <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 DrawVerticalThumb (Graphics g, Rectangle bounds, ScrollBarState state) { if (!IsSupported) throw new InvalidOperationException (); VisualStyleRenderer vsr; switch (state) { case ScrollBarState.Disabled: vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ThumbButtonVertical.Disabled); break; case ScrollBarState.Hot: vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ThumbButtonVertical.Hot); break; case ScrollBarState.Normal: default: vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ThumbButtonVertical.Normal); break; case ScrollBarState.Pressed: vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.ThumbButtonVertical.Pressed); break; } vsr.DrawBackground (g, bounds); }
public static Size GetSizeBoxSize (Graphics g, ScrollBarState state) { if (!IsSupported) throw new InvalidOperationException (); VisualStyleRenderer vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.SizeBox.LeftAlign); return vsr.GetPartSize(g, ThemeSizeType.Draw); }
public void DrawTrack(Graphics g, Rectangle rect, ScrollBarState state, ScrollBarOrientation orientation) { g.FillRectangle(TrackBrush, rect); }
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] // Using Graphics instead of IDeviceContext intentionally public static void DrawVerticalThumb(Graphics g, Rectangle bounds, ScrollBarState state) { InitializeRenderer(VisualStyleElement.ScrollBar.ThumbButtonVertical.Normal, (int)state); visualStyleRenderer.DrawBackground(g, bounds); }
/// <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(); } }
public override void OnMouseIsDown(BasicMouseEventArgs e) { ScrollBarState newState = ScrollBarState.Neutral; bool ctrl = e.ControlPressed; if (e.Y < GraphUtil.scrollBarWidth - 1){ if (ctrl){ newState = ScrollBarState.PressFirstBox; MoveUp(main.DeltaUpToSelection()); } else{ newState = ScrollBarState.PressFirstBox; MoveUp(main.DeltaY()); upThread = new Thread(() => WalkUp(main.DeltaY())); upThread.Start(); } } else if (e.Y > e.Height - GraphUtil.scrollBarWidth){ if (ctrl){ newState = ScrollBarState.PressSecondBox; MoveDown(main.DeltaDownToSelection()); } else{ newState = ScrollBarState.PressSecondBox; MoveDown(main.DeltaY()); downThread = new Thread(() => WalkDown(main.DeltaY())); downThread.Start(); } } else if (HasBar){ int s = CalcBarStart(e.Height); int l = CalcBarSize(e.Height); if (e.Y >= s && e.Y <= s + l){ newState = ScrollBarState.PressBar; dragStart = e.Y; visibleDragStart = main.VisibleY; } else if (e.Y < s){ MoveUp((int) (main.VisibleHeight / main.ZoomFactor)); upThread = new Thread(() => WalkUp((int) (main.VisibleHeight / main.ZoomFactor))); upThread.Start(); } else{ MoveDown((int) (main.VisibleHeight / main.ZoomFactor)); downThread = new Thread(() => WalkDown((int) (main.VisibleHeight / main.ZoomFactor))); downThread.Start(); } } if (newState != state){ state = newState; Invalidate(); } }
/// <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 channel ( or track ). /// </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 scrollbar state.</param> /// <param name="orientation">The <see cref="ScrollBarOrientation"/>.</param> public static void DrawTrack( Graphics g, Rectangle rect, ScrollBarState state, ScrollBarOrientation orientation) { if (g == null) { throw new ArgumentNullException("g"); } if (rect.Width <= 0 || rect.Height <= 0 || state != ScrollBarState.Pressed || g.IsVisibleClipEmpty || !g.VisibleClipBounds.IntersectsWith(rect)) { return; } if (orientation == ScrollBarOrientation.Vertical) { DrawTrackVertical(g, rect); } else { DrawTrackHorizontal(g, rect); } }
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] // Using Graphics instead of IDeviceContext intentionally public static void DrawHorizontalThumbGrip(Graphics g, Rectangle bounds, ScrollBarState state) { InitializeRenderer(VisualStyleElement.ScrollBar.GripperHorizontal.Normal, (int)state); visualStyleRenderer.DrawBackground(g, bounds); }