2 // System.Windows.Forms.ScrollBar.cs
4 // Permission is hereby granted, free of charge, to any person obtaining
5 // a copy of this software and associated documentation files (the
6 // "Software"), to deal in the Software without restriction, including
7 // without limitation the rights to use, copy, modify, merge, publish,
8 // distribute, sublicense, and/or sell copies of the Software, and to
9 // permit persons to whom the Software is furnished to do so, subject to
10 // the following conditions:
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 // Copyright (C) 2004, Novell, Inc.
26 // Jordi Mas i Hernandez jordi@ximian.com
33 using System.Drawing.Imaging;
34 using System.Drawing.Drawing2D;
35 using System.ComponentModel;
36 using System.Runtime.InteropServices;
38 namespace System.Windows.Forms
40 [DefaultEvent ("Scroll")]
41 [DefaultProperty ("Value")]
42 public abstract class ScrollBar : Control
44 #region Local Variables
48 private int large_change;
49 private int small_change;
50 internal int scrollbutton_height;
51 internal int scrollbutton_width;
52 private ScrollBars type;
53 private Rectangle first_arrow_area = new Rectangle (); // up or left
54 private Rectangle second_arrow_area = new Rectangle (); // down or right
55 private Rectangle thumb_pos = new Rectangle ();
56 private Rectangle thumb_area = new Rectangle ();
57 internal ButtonState firstbutton_state = ButtonState.Normal;
58 internal ButtonState secondbutton_state = ButtonState.Normal;
59 private bool firstbutton_pressed = false;
60 private bool secondbutton_pressed = false;
61 private bool thumb_pressed = false;
62 private float pixel_per_pos = 0;
63 private Timer timer = new Timer ();
64 private TimerType timer_type;
65 private int thumb_pixel_click_move;
66 private int thumb_pixel_click_move_prev;
67 private int thumb_size = 40;
68 private const int thumb_min_size = 8;
69 private const int thumb_notshown_size = 40;
71 private int lastclick_pos; // Position of the last button-down event
72 private int lastclick_pos_thumb; // Position of the last button-down event relative to the thumb
73 private bool outside_thumbarea_right = false;
74 private bool outside_thumbarea_left = false;
76 private Rectangle dirty;
78 internal ThumbMoving thumb_moving = ThumbMoving.None;
79 #endregion // Local Variables
81 private enum TimerType
89 internal enum ThumbMoving
97 public new event EventHandler BackColorChanged;
98 public new event EventHandler BackgroundImageChanged;
99 public new event EventHandler Click;
100 public new event EventHandler DoubleClick;
101 public new event EventHandler FontChanged;
102 public new event EventHandler ForeColorChanged;
103 public new event EventHandler ImeModeChanged;
104 public new event MouseEventHandler MouseDown;
105 public new event MouseEventHandler MouseMove;
106 public new event MouseEventHandler MouseUp;
107 public new event PaintEventHandler Paint;
108 public event ScrollEventHandler Scroll;
109 public new event EventHandler TextChanged;
110 public event EventHandler ValueChanged;
121 timer.Tick += new EventHandler (OnTimer);
122 base.KeyDown += new KeyEventHandler (OnKeyDownSB);
123 base.MouseDown += new MouseEventHandler (OnMouseDownSB);
124 base.MouseUp += new MouseEventHandler (OnMouseUpSB);
125 base.MouseMove += new MouseEventHandler (OnMouseMoveSB);
126 base.Resize += new EventHandler (OnResizeSB);
127 base.TabStop = false;
129 if (ThemeEngine.Current.DoubleBufferingSupported == true) {
130 double_buffering = true;
132 double_buffering = false;
135 SetStyle (ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
136 SetStyle (ControlStyles.ResizeRedraw | ControlStyles.Opaque, true);
139 #region Internal & Private Properties
140 internal Rectangle FirstArrowArea {
142 return this.first_arrow_area;
146 this.first_arrow_area = value;
150 internal Rectangle SecondArrowArea {
152 return this.second_arrow_area;
156 this.second_arrow_area = value;
160 internal Rectangle ThumbPos {
169 #endregion // Internal & Private Properties
171 #region Public Properties
173 [EditorBrowsable (EditorBrowsableState.Never)]
174 public override Color BackColor
176 get { return base.BackColor; }
178 if (base.BackColor == value)
181 if (BackColorChanged != null)
182 BackColorChanged (this, EventArgs.Empty);
184 base.BackColor = value;
189 [EditorBrowsable (EditorBrowsableState.Never)]
190 public override Image BackgroundImage
192 get { return base.BackgroundImage; }
194 if (base.BackgroundImage == value)
197 if (BackgroundImageChanged != null)
198 BackgroundImageChanged (this, EventArgs.Empty);
200 base.BackgroundImage = value;
204 protected override CreateParams CreateParams
206 get { return base.CreateParams; }
209 protected override ImeMode DefaultImeMode
211 get { return ImeMode.Disable; }
214 public override Font Font
216 get { return base.Font; }
218 if (base.Font == value)
221 if (FontChanged != null)
222 FontChanged (this, EventArgs.Empty);
228 [EditorBrowsable (EditorBrowsableState.Never)]
229 public override Color ForeColor
231 get { return base.ForeColor; }
233 if (base.ForeColor == value)
236 if (ForeColorChanged != null)
237 ForeColorChanged (this, EventArgs.Empty);
239 base.ForeColor = value;
244 [EditorBrowsable (EditorBrowsableState.Never)]
245 public new ImeMode ImeMode
247 get { return base.ImeMode; }
249 if (base.ImeMode == value)
252 if (ImeModeChanged != null)
253 ImeModeChanged (this, EventArgs.Empty);
255 base.ImeMode = value;
259 public int LargeChange {
261 if (large_change > maximum)
262 return (maximum + 1);
268 throw new Exception( string.Format("Value '{0}' must be greater than or equal to 0.", value));
270 if (large_change != value) {
271 large_change = value;
273 // thumb area depends on large change value,
274 // so we need to recalculate it.
276 UpdatePos (Value, true);
283 get { return maximum; }
287 if (maximum < minimum)
290 // thumb area depends on maximum value,
291 // so we need to recalculate it.
293 UpdatePos (Value, true);
299 get { return minimum; }
303 if (minimum > maximum)
306 // thumb area depends on minimum value,
307 // so we need to recalculate it.
309 UpdatePos (Value, true);
314 public int SmallChange {
315 get { return small_change; }
318 throw new Exception( string.Format("Value '{0}' must be greater than or equal to 0.", value));
320 if (small_change != value) {
321 small_change = value;
322 UpdatePos (Value, true);
328 public new bool TabStop {
329 get { return base.TabStop; }
330 set { base.TabStop = value; }
333 [EditorBrowsable (EditorBrowsableState.Never)]
334 public override string Text {
335 get { return base.Text; }
336 set { base.Text = value; }
340 get { return position; }
342 if ( value < minimum || value > maximum )
343 throw new ArgumentException(
344 string.Format("'{0}' is not a valid value for 'Value'. 'Value' should be between 'Minimum' and 'Maximum'", value));
346 if (position != value){
349 OnValueChanged (EventArgs.Empty);
352 UpdatePos (Value, true);
358 #endregion //Public Properties
360 #region Public Methods
362 protected override void OnEnabledChanged (EventArgs e)
364 base.OnEnabledChanged (e);
367 firstbutton_state = secondbutton_state = ButtonState.Normal;
369 firstbutton_state = secondbutton_state = ButtonState.Inactive;
374 protected override void OnHandleCreated (System.EventArgs e)
376 base.OnHandleCreated (e);
380 UpdatePos (Value, true);
383 protected virtual void OnScroll (ScrollEventArgs event_args)
388 Scroll (this, event_args);
391 protected virtual void OnValueChanged (EventArgs e)
393 if (ValueChanged != null)
394 ValueChanged (this, e);
397 public override string ToString()
399 return string.Format("{0}, Minimum: {1}, Maximum: {2}, Value: {3}",
400 GetType( ).FullName.ToString( ), minimum, maximum, position);
403 protected void UpdateScrollInfo ()
408 protected override void WndProc (ref Message m)
414 PaintEventArgs paint_event;
416 paint_event = XplatUI.PaintEventStart (Handle);
417 OnPaintSB (paint_event);
418 XplatUI.PaintEventEnd (Handle);
423 case Msg.WM_ERASEBKGND:
424 m.Result = (IntPtr) 1; /// Disable background painting to avoid flickering
431 base.WndProc (ref m);
434 #endregion //Public Methods
436 #region Private Methods
438 private void CalcButtonSizes ()
441 if (Height < ThemeEngine.Current.ScrollBarButtonSize * 2)
442 scrollbutton_height = Height /2;
444 scrollbutton_height = ThemeEngine.Current.ScrollBarButtonSize;
447 if (Width < ThemeEngine.Current.ScrollBarButtonSize * 2)
448 scrollbutton_width = Width /2;
450 scrollbutton_width = ThemeEngine.Current.ScrollBarButtonSize;
454 private void CalcThumbArea ()
459 thumb_area.Height = Height - scrollbutton_height - scrollbutton_height;
461 thumb_area.Y = scrollbutton_height;
462 thumb_area.Width = Width;
464 if (Height < thumb_notshown_size)
467 double per = ((double) this.LargeChange / (double)((1 + maximum - minimum)));
468 thumb_size = 1 + (int) (thumb_area.Height * per);
470 if (thumb_size < thumb_min_size)
471 thumb_size = thumb_min_size;
474 pixel_per_pos = ((float)(thumb_area.Height - thumb_size) / (float) ((maximum - minimum - this.LargeChange) + 1));
479 thumb_area.X = scrollbutton_width;
480 thumb_area.Height = Height;
481 thumb_area.Width = Width - scrollbutton_width - scrollbutton_width;
483 if (Width < thumb_notshown_size)
486 double per = ((double) this.LargeChange / (double)((1 + maximum - minimum)));
487 thumb_size = 1 + (int) (thumb_area.Width * per);
489 if (thumb_size < thumb_min_size)
490 thumb_size = thumb_min_size;
493 pixel_per_pos = ((float)(thumb_area.Width - thumb_size) / (float) ((maximum - minimum - this.LargeChange) + 1));
497 private void Draw (Rectangle clip)
499 ThemeEngine.Current.DrawScrollBar(DeviceContext, clip, this);
502 private void LargeIncrement ()
504 UpdatePos (position + large_change, true);
506 OnScroll (new ScrollEventArgs (ScrollEventType.LargeIncrement, position));
507 OnScroll (new ScrollEventArgs (ScrollEventType.EndScroll, position));
510 private void LargeDecrement ()
512 UpdatePos (position - large_change, true);
514 OnScroll (new ScrollEventArgs (ScrollEventType.LargeDecrement, position));
515 OnScroll (new ScrollEventArgs (ScrollEventType.EndScroll, position));
518 private void OnResizeSB (Object o, EventArgs e)
520 if (Width <= 0 || Height <= 0)
525 UpdatePos (position, true);
528 private void OnPaintSB (PaintEventArgs pevent)
531 Paint (this, pevent);
534 if (Width <= 0 || Height <= 0 || Visible == false)
537 Draw (pevent.ClipRectangle);
538 pevent.Graphics.DrawImage (ImageBuffer, pevent.ClipRectangle, pevent.ClipRectangle, GraphicsUnit.Pixel);
541 private void OnTimer (Object source, EventArgs e)
545 switch (timer_type) {
547 case TimerType.HoldButton:
548 SetRepeatButtonTimer ();
551 case TimerType.RepeatButton:
553 if ((firstbutton_state & ButtonState.Pushed) == ButtonState.Pushed)
556 if ((secondbutton_state & ButtonState.Pushed) == ButtonState.Pushed)
562 case TimerType.HoldThumbArea:
563 SetRepeatThumbAreaTimer ();
566 case TimerType.RepeatThumbArea:
568 Point pnt, pnt_screen;
569 Rectangle thumb_area_screen = thumb_area;
571 pnt_screen = PointToScreen (new Point (thumb_area.X, thumb_area.Y));
572 thumb_area_screen.X = pnt_screen.X;
573 thumb_area_screen.Y = pnt_screen.Y;
575 if (thumb_area_screen.Contains (MousePosition) == false) {
576 timer.Enabled = false;
577 thumb_moving = ThumbMoving.None;
582 pnt = PointToClient (MousePosition);
585 lastclick_pos = pnt.Y;
587 lastclick_pos = pnt.X;
589 if (thumb_moving == ThumbMoving.Forward) {
590 if ((vert && (thumb_pos.Y + thumb_size > lastclick_pos)) ||
591 (!vert && (thumb_pos.X + thumb_size > lastclick_pos)) ||
592 (thumb_area.Contains (pnt) == false)){
593 timer.Enabled = false;
594 thumb_moving = ThumbMoving.None;
602 if ((vert && (thumb_pos.Y < lastclick_pos)) ||
603 (!vert && (thumb_pos.X < lastclick_pos))){
604 timer.Enabled = false;
605 thumb_moving = ThumbMoving.None;
620 private void OnMouseMoveSB (object sender, MouseEventArgs e)
622 if (MouseMove != null) {
626 if (Enabled == false || thumb_size == 0)
629 if (firstbutton_pressed) {
630 if (!first_arrow_area.Contains (e.X, e.Y) && ((firstbutton_state & ButtonState.Pushed) == ButtonState.Pushed)) {
631 firstbutton_state = ButtonState.Normal;
632 Invalidate (first_arrow_area);
634 } else if (first_arrow_area.Contains (e.X, e.Y) && ((firstbutton_state & ButtonState.Normal) == ButtonState.Normal)) {
635 firstbutton_state = ButtonState.Pushed;
636 Invalidate (first_arrow_area);
639 } else if (secondbutton_pressed) {
640 if (!second_arrow_area.Contains (e.X, e.Y) && ((secondbutton_state & ButtonState.Pushed) == ButtonState.Pushed)) {
641 secondbutton_state = ButtonState.Normal;
642 Invalidate (second_arrow_area);
644 } else if (second_arrow_area.Contains (e.X, e.Y) && ((secondbutton_state & ButtonState.Normal) == ButtonState.Normal)) {
645 secondbutton_state = ButtonState.Pushed;
646 Invalidate (second_arrow_area);
649 } else if (thumb_pressed == true) {
654 int mouse_click = e.Y;
655 int outside_curpos = thumb_area.Y + thumb_area.Height - thumb_size + lastclick_pos_thumb;
658 if (mouse_click > thumb_area.Y + thumb_area.Height) {
659 outside_thumbarea_right = true;
660 mouse_click = thumb_area.Y + thumb_area.Height;
663 if (mouse_click < thumb_area.Y) {
664 outside_thumbarea_left = true;
665 mouse_click = thumb_area.Y;
668 if (outside_thumbarea_right && mouse_click < outside_curpos) {
669 outside_thumbarea_right = false;
670 thumb_pixel_click_move_prev =
671 thumb_pixel_click_move = outside_curpos;
674 if (outside_thumbarea_left && mouse_click > thumb_area.Y + lastclick_pos_thumb) {
675 outside_thumbarea_left = false;
676 thumb_pixel_click_move_prev =
677 thumb_pixel_click_move = thumb_area.Y + lastclick_pos_thumb;
680 if (outside_thumbarea_right == false && outside_thumbarea_left == false) {
681 pixel_pos = thumb_pos.Y + (thumb_pixel_click_move - thumb_pixel_click_move_prev);
682 thumb_pixel_click_move_prev = thumb_pixel_click_move;
683 thumb_pixel_click_move = mouse_click;
684 UpdateThumbPos (pixel_pos, true);
689 int mouse_click = e.X;
690 int outside_curpos = thumb_area.X + thumb_area.Width - thumb_size + lastclick_pos_thumb;
692 if (mouse_click > thumb_area.X + thumb_area.Width) {
693 outside_thumbarea_right = true;
694 mouse_click = thumb_area.X + thumb_area.Width;
697 if (mouse_click < thumb_area.X) {
698 outside_thumbarea_left = true;
699 mouse_click = thumb_area.X;
702 if (outside_thumbarea_right && mouse_click < outside_curpos) {
703 outside_thumbarea_right = false;
704 thumb_pixel_click_move_prev =
705 thumb_pixel_click_move = outside_curpos;
708 if (outside_thumbarea_left && mouse_click > thumb_area.X + lastclick_pos_thumb) {
709 outside_thumbarea_left = false;
710 thumb_pixel_click_move_prev =
711 thumb_pixel_click_move = thumb_area.X + lastclick_pos_thumb;
714 if (outside_thumbarea_right == false && outside_thumbarea_left == false) {
715 pixel_pos = thumb_pos.X + (thumb_pixel_click_move - thumb_pixel_click_move_prev);
716 thumb_pixel_click_move_prev = thumb_pixel_click_move;
717 thumb_pixel_click_move = mouse_click;
718 UpdateThumbPos (pixel_pos, true);
728 private void OnMouseDownSB (object sender, MouseEventArgs e)
732 if (e.Button == MouseButtons.Right) {
733 if (MouseDown != null) {
738 if (Enabled == false)
741 if (firstbutton_state != ButtonState.Inactive && first_arrow_area.Contains (e.X, e.Y)) {
743 firstbutton_state = ButtonState.Pushed;
744 firstbutton_pressed = true;
745 Invalidate (first_arrow_area);
746 if (!timer.Enabled) {
747 SetHoldButtonClickTimer ();
748 timer.Enabled = true;
752 if (secondbutton_state != ButtonState.Inactive && second_arrow_area.Contains (e.X, e.Y)) {
754 secondbutton_state = ButtonState.Pushed;
755 secondbutton_pressed = true;
756 Invalidate (second_arrow_area);
757 if (!timer.Enabled) {
758 SetHoldButtonClickTimer ();
759 timer.Enabled = true;
763 if (thumb_size > 0 && thumb_pos.Contains (e.X, e.Y)) {
764 thumb_pressed = true;
767 lastclick_pos_thumb = e.Y - thumb_pos.Y;
769 thumb_pixel_click_move_prev = thumb_pixel_click_move = e.Y;
772 lastclick_pos_thumb = e.X - thumb_pos.X;
774 thumb_pixel_click_move_prev = thumb_pixel_click_move = e.X;
777 if (thumb_size > 0 && thumb_area.Contains (e.X, e.Y)) {
780 lastclick_pos_thumb = e.Y - thumb_pos.Y;
783 if (e.Y > thumb_pos.Y + thumb_pos.Height) {
785 thumb_moving = ThumbMoving.Forward;
786 Dirty (new Rectangle (0, thumb_pos.Y + thumb_pos.Height,
787 ClientRectangle.Width,
788 ClientRectangle.Height - (thumb_pos.Y + thumb_pos.Height) -
789 scrollbutton_height));
792 thumb_moving = ThumbMoving.Backwards;
793 Dirty (new Rectangle (0, scrollbutton_height,
794 ClientRectangle.Width,
795 thumb_pos.Y - scrollbutton_height));
799 lastclick_pos_thumb = e.X - thumb_pos.X;
802 if (e.X > thumb_pos.X + thumb_pos.Width) {
803 thumb_moving = ThumbMoving.Forward;
805 Dirty (new Rectangle (thumb_pos.X + thumb_pos.Width, 0,
806 ClientRectangle.Width - (thumb_pos.X + thumb_pos.Width) -
808 ClientRectangle.Height));
810 thumb_moving = ThumbMoving.Backwards;
812 Dirty (new Rectangle (scrollbutton_width, 0,
813 thumb_pos.X - scrollbutton_width,
814 ClientRectangle.Height));
818 SetHoldThumbAreaTimer ();
819 timer.Enabled = true;
825 private void OnMouseUpSB (object sender, MouseEventArgs e)
829 if (e.Button == MouseButtons.Right) {
830 if (MouseUp != null) {
835 if (Enabled == false)
838 timer.Enabled = false;
839 if (thumb_moving != ThumbMoving.None) {
841 thumb_moving = ThumbMoving.None;
843 this.Capture = false;
845 if (firstbutton_pressed) {
846 firstbutton_state = ButtonState.Normal;
847 if (first_arrow_area.Contains (e.X, e.Y)) {
850 firstbutton_pressed = false;
851 Dirty (first_arrow_area);
852 } else if (secondbutton_pressed) {
853 secondbutton_state = ButtonState.Normal;
854 if (second_arrow_area.Contains (e.X, e.Y)) {
857 Dirty (second_arrow_area);
858 secondbutton_pressed = false;
859 } else if (thumb_pressed == true) {
860 OnScroll (new ScrollEventArgs (ScrollEventType.ThumbPosition, position));
861 OnScroll (new ScrollEventArgs (ScrollEventType.EndScroll, position));
862 thumb_pressed = false;
870 private void OnKeyDownSB (Object o, KeyEventArgs key)
872 if (Enabled == false)
877 switch (key.KeyCode){
915 private void SmallIncrement ()
917 UpdatePos (position + small_change, true);
919 OnScroll (new ScrollEventArgs (ScrollEventType.SmallIncrement, position));
920 OnScroll (new ScrollEventArgs (ScrollEventType.EndScroll, position));
923 private void SmallDecrement ()
925 UpdatePos (position - small_change, true);
927 OnScroll (new ScrollEventArgs (ScrollEventType.SmallDecrement, position));
928 OnScroll (new ScrollEventArgs (ScrollEventType.EndScroll, position));
931 private void SetHoldButtonClickTimer ()
933 timer.Enabled = false;
934 timer.Interval = 200;
935 timer_type = TimerType.HoldButton;
936 timer.Enabled = true;
939 private void SetRepeatButtonTimer ()
941 timer.Enabled = false;
943 timer_type = TimerType.RepeatButton;
944 timer.Enabled = true;
947 private void SetHoldThumbAreaTimer ()
949 timer.Enabled = false;
950 timer.Interval = 200;
951 timer_type = TimerType.HoldThumbArea;
952 timer.Enabled = true;
955 private void SetRepeatThumbAreaTimer ()
957 timer.Enabled = false;
959 timer_type = TimerType.RepeatThumbArea;
960 timer.Enabled = true;
963 private void UpdatePos (int newPos, bool update_thumbpos)
968 if (newPos < minimum)
971 if (newPos > maximum + 1 - large_change)
972 pos = maximum + 1 - large_change;
976 // pos can't be less than minimum
980 if (update_thumbpos) {
982 UpdateThumbPos (thumb_area.Y + (int)(((float)(pos - minimum)) * pixel_per_pos), false);
984 UpdateThumbPos (thumb_area.X + (int)(((float)(pos - minimum)) * pixel_per_pos), false);
988 position = pos; // Updates directly the value to avoid thumb pos update
990 if (ValueChanged != null)
991 ValueChanged (this, EventArgs.Empty);
994 if (pos != old) // Fire event
995 OnScroll (new ScrollEventArgs (ScrollEventType.ThumbTrack, pos));
999 private void UpdateThumbPos (int pixel, bool update_value)
1005 if (pixel < thumb_area.Y)
1006 thumb_pos.Y = thumb_area.Y;
1008 if (pixel > thumb_area.Y + thumb_area.Height - thumb_size)
1009 thumb_pos.Y = thumb_area.Y + thumb_area.Height - thumb_size;
1011 thumb_pos.Y = pixel;
1014 thumb_pos.Width = ThemeEngine.Current.ScrollBarButtonSize;
1015 thumb_pos.Height = thumb_size;
1016 new_pos = (float) (thumb_pos.Y - thumb_area.Y);
1017 new_pos = new_pos / pixel_per_pos;
1022 if (pixel < thumb_area.X)
1023 thumb_pos.X = thumb_area.X;
1025 if (pixel > thumb_area.X + thumb_area.Width - thumb_size)
1026 thumb_pos.X = thumb_area.X + thumb_area.Width - thumb_size;
1028 thumb_pos.X = pixel;
1031 thumb_pos.Width = thumb_size;
1032 thumb_pos.Height = ThemeEngine.Current.ScrollBarButtonSize;
1033 new_pos = (float) (thumb_pos.X - thumb_area.X);
1034 new_pos = new_pos / pixel_per_pos;
1040 UpdatePos ((int) new_pos + minimum, false);
1043 private void SetValue (int value)
1045 if ( value < minimum || value > maximum )
1046 throw new ArgumentException(
1047 String.Format("'{0}' is not a valid value for 'Value'. 'Value' should be between 'Minimum' and 'Maximum'", value));
1049 if (position != value){
1052 OnValueChanged (EventArgs.Empty);
1053 UpdatePos (value, true);
1057 private void ClearDirty ()
1059 dirty = Rectangle.Empty;
1062 private void Dirty (Rectangle r)
1064 if (dirty == Rectangle.Empty) {
1068 dirty = Rectangle.Union (dirty, r);
1071 private void DirtyThumbArea ()
1073 if (thumb_moving == ThumbMoving.Forward) {
1075 Dirty (new Rectangle (0, thumb_pos.Y + thumb_pos.Height,
1076 ClientRectangle.Width,
1077 ClientRectangle.Height - (thumb_pos.Y + thumb_pos.Height) -
1078 scrollbutton_height));
1080 Dirty (new Rectangle (thumb_pos.X + thumb_pos.Width, 0,
1081 ClientRectangle.Width - (thumb_pos.X + thumb_pos.Width) -
1083 ClientRectangle.Height));
1085 } else if (thumb_moving == ThumbMoving.Backwards) {
1087 Dirty(new Rectangle (0, scrollbutton_height,
1088 ClientRectangle.Width,
1089 thumb_pos.Y - scrollbutton_height));
1091 Dirty (new Rectangle (scrollbutton_width, 0,
1092 thumb_pos.X - scrollbutton_width,
1093 ClientRectangle.Height));
1098 private void InvalidateDirty ()
1101 dirty = Rectangle.Empty;
1104 #endregion //Private Methods