1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905
|
//
// System.Windows.Forms.TrackBar.cs
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//
// Copyright (c) 2004-2006 Novell, Inc.
//
// Authors:
// Jordi Mas i Hernandez, jordi@ximian.com
// Rolf Bjarne Kvinge, RKvinge@novell.com
//
// TODO:
// - The AutoSize functionality seems quite broken for vertical controls in .Net 1.1. Not
// sure if we are implementing it the right way.
//
// NOT COMPLETE
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
using System.Timers;
using System.Runtime.InteropServices;
namespace System.Windows.Forms
{
[DefaultBindingProperty ("Value")]
[ComVisible (true)]
[ClassInterface (ClassInterfaceType.AutoDispatch)]
[Designer("System.Windows.Forms.Design.TrackBarDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
[DefaultEvent ("Scroll")]
[DefaultProperty("Value")]
public class TrackBar : Control, ISupportInitialize
{
private int minimum;
private int maximum;
internal int tickFrequency;
private bool autosize;
private int position;
private int smallChange;
private int largeChange;
private Orientation orientation;
private TickStyle tickStyle;
private Rectangle thumb_pos = new Rectangle (); /* Current position and size of the thumb */
private Rectangle thumb_area = new Rectangle (); /* Area where the thumb can scroll */
internal bool thumb_pressed = false;
private System.Timers.Timer holdclick_timer = new System.Timers.Timer ();
internal int thumb_mouseclick;
private bool mouse_clickmove;
private bool is_moving_right; // which way the thumb should move when mouse is down (right=up, left=down)
internal int mouse_down_x_offset; // how far from left side of thumb was the mouse clicked.
internal bool mouse_moved; // has the mouse moved since it was clicked?
private const int size_of_autosize = 45;
private bool right_to_left_layout;
bool thumb_entered;
#region events
[EditorBrowsable (EditorBrowsableState.Always)]
[Browsable (true)]
public new event EventHandler AutoSizeChanged {
add {base.AutoSizeChanged += value;}
remove {base.AutoSizeChanged -= value;}
}
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
public new event EventHandler BackgroundImageChanged {
add { base.BackgroundImageChanged += value; }
remove { base.BackgroundImageChanged -= value; }
}
[EditorBrowsable (EditorBrowsableState.Never)]
[Browsable (false)]
public new event EventHandler BackgroundImageLayoutChanged
{
add { base.BackgroundImageLayoutChanged += value; }
remove { base.BackgroundImageLayoutChanged -= value; }
}
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
public new event EventHandler Click {
add { base.Click += value; }
remove { base.Click -= value; }
}
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
public new event EventHandler DoubleClick {
add { base.DoubleClick += value; }
remove { base.DoubleClick -= value; }
}
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
public new event EventHandler FontChanged {
add { base.FontChanged += value; }
remove { base.FontChanged -= value; }
}
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
public new event EventHandler ForeColorChanged {
add { base.ForeColorChanged += value; }
remove { base.ForeColorChanged -= value; }
}
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
public new event EventHandler ImeModeChanged {
add { base.ImeModeChanged += value; }
remove { base.ImeModeChanged -= value; }
}
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
public new event MouseEventHandler MouseClick {
add {base.MouseClick += value;}
remove {base.MouseClick -= value;}
}
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
public new event MouseEventHandler MouseDoubleClick
{
add { base.MouseDoubleClick += value; }
remove { base.MouseDoubleClick -= value; }
}
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
public new event EventHandler PaddingChanged
{
add { base.PaddingChanged += value; }
remove { base.PaddingChanged -= value; }
}
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
public new event PaintEventHandler Paint {
add { base.Paint += value; }
remove { base.Paint -= value; }
}
public event EventHandler RightToLeftLayoutChanged {
add {Events.AddHandler (RightToLeftLayoutChangedEvent, value);}
remove {Events.RemoveHandler (RightToLeftLayoutChangedEvent, value);}
}
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
public new event EventHandler TextChanged {
add { base.TextChanged += value; }
remove { base.TextChanged -= value; }
}
static object RightToLeftLayoutChangedEvent = new object ();
static object ScrollEvent = new object ();
static object ValueChangedEvent = new object ();
public event EventHandler Scroll {
add { Events.AddHandler (ScrollEvent, value); }
remove { Events.RemoveHandler (ScrollEvent, value); }
}
public event EventHandler ValueChanged {
add { Events.AddHandler (ValueChangedEvent, value); }
remove { Events.RemoveHandler (ValueChangedEvent, value); }
}
#endregion // Events
#region UIA FrameWork Events
static object UIAValueParamChangedEvent = new object ();
internal event EventHandler UIAValueParamChanged {
add { Events.AddHandler (UIAValueParamChangedEvent, value); }
remove { Events.RemoveHandler (UIAValueParamChangedEvent, value); }
}
internal void OnUIAValueParamChanged ()
{
EventHandler eh = (EventHandler) Events [UIAValueParamChangedEvent];
if (eh != null)
eh (this, EventArgs.Empty);
}
#endregion
public TrackBar ()
{
orientation = Orientation.Horizontal;
minimum = 0;
maximum = 10;
tickFrequency = 1;
autosize = true;
position = 0;
tickStyle = TickStyle.BottomRight;
smallChange = 1;
largeChange = 5;
mouse_clickmove = false;
MouseDown += new MouseEventHandler (OnMouseDownTB);
MouseUp += new MouseEventHandler (OnMouseUpTB);
MouseMove += new MouseEventHandler (OnMouseMoveTB);
MouseLeave += new EventHandler (OnMouseLeave);
KeyDown += new KeyEventHandler (OnKeyDownTB);
LostFocus += new EventHandler (OnLostFocusTB);
GotFocus += new EventHandler (OnGotFocusTB);
holdclick_timer.Elapsed += new ElapsedEventHandler (OnFirstClickTimer);
SetStyle (ControlStyles.UserPaint | ControlStyles.Opaque | ControlStyles.UseTextForAccessibility, false);
}
#region Private & Internal Properties
internal Rectangle ThumbPos {
get {
return thumb_pos;
}
set {
thumb_pos = value;
}
}
internal Rectangle ThumbArea {
get {
return thumb_area;
}
set {
thumb_area = value;
}
}
internal bool ThumbEntered {
get { return thumb_entered; }
set {
if (thumb_entered == value)
return;
thumb_entered = value;
if (ThemeEngine.Current.TrackBarHasHotThumbStyle)
Invalidate (GetRealThumbRectangle ());
}
}
#endregion // Private & Internal Properties
#region Public Properties
[Browsable (true)]
[EditorBrowsable (EditorBrowsableState.Always)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Visible)]
[DefaultValue (true)]
public override bool AutoSize {
get { return autosize; }
set { autosize = value;}
}
[EditorBrowsable (EditorBrowsableState.Never)]
[Browsable (false)]
public override Image BackgroundImage {
get { return base.BackgroundImage; }
set { base.BackgroundImage = value; }
}
[EditorBrowsable (EditorBrowsableState.Never)]
[Browsable (false)]
public override ImageLayout BackgroundImageLayout {
get {
return base.BackgroundImageLayout;
}
set {
base.BackgroundImageLayout = value;
}
}
protected override CreateParams CreateParams {
get {
return base.CreateParams;
}
}
protected override ImeMode DefaultImeMode {
get {return ImeMode.Disable; }
}
protected override Size DefaultSize {
get { return ThemeEngine.Current.TrackBarDefaultSize; }
}
[EditorBrowsable (EditorBrowsableState.Never)]
protected override bool DoubleBuffered {
get {
return base.DoubleBuffered;
}
set {
base.DoubleBuffered = value;
}
}
[Browsable(false)]
[EditorBrowsable (EditorBrowsableState.Never)]
public override Font Font {
get { return base.Font; }
set { base.Font = value; }
}
[EditorBrowsable (EditorBrowsableState.Never)]
[Browsable (false)]
public override Color ForeColor {
get { return base.ForeColor; }
set { base.ForeColor = value; }
}
[EditorBrowsable (EditorBrowsableState.Never)]
[Browsable (false)]
public new ImeMode ImeMode {
get { return base.ImeMode; }
set { base.ImeMode = value; }
}
[DefaultValue (5)]
public int LargeChange
{
get { return largeChange; }
set {
if (value < 0)
throw new ArgumentOutOfRangeException (string.Format ("Value '{0}' must be greater than or equal to 0.", value));
largeChange = value;
OnUIAValueParamChanged ();
}
}
[DefaultValue (10)]
[RefreshProperties (RefreshProperties.All)]
public int Maximum {
get { return maximum; }
set {
if (maximum != value) {
maximum = value;
if (maximum < minimum)
minimum = maximum;
Refresh ();
OnUIAValueParamChanged ();
}
}
}
[DefaultValue (0)]
[RefreshProperties (RefreshProperties.All)]
public int Minimum {
get { return minimum; }
set {
if (Minimum != value) {
minimum = value;
if (minimum > maximum)
maximum = minimum;
Refresh ();
OnUIAValueParamChanged ();
}
}
}
[DefaultValue (Orientation.Horizontal)]
[Localizable (true)]
public Orientation Orientation {
get { return orientation; }
set {
if (!Enum.IsDefined (typeof (Orientation), value))
throw new InvalidEnumArgumentException (string.Format("Enum argument value '{0}' is not valid for Orientation", value));
/* Orientation can be changed once the control has been created */
if (orientation != value) {
orientation = value;
if (this.IsHandleCreated) {
Size = new Size (Height, Width);
Refresh ();
}
}
}
}
[Browsable (false)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
[EditorBrowsable (EditorBrowsableState.Never)]
public new Padding Padding {
get {
return base.Padding;
}
set {
base.Padding = value;
}
}
[Localizable (true)]
[DefaultValue (false)]
public virtual bool RightToLeftLayout {
get {
return right_to_left_layout;
}
set {
if (value != right_to_left_layout) {
right_to_left_layout = value;
OnRightToLeftLayoutChanged (EventArgs.Empty);
}
}
}
[DefaultValue (1)]
public int SmallChange {
get { return smallChange;}
set {
if (value < 0)
throw new ArgumentOutOfRangeException (string.Format ("Value '{0}' must be greater than or equal to 0.", value));
if (smallChange != value) {
smallChange = value;
OnUIAValueParamChanged ();
}
}
}
[EditorBrowsable (EditorBrowsableState.Never)]
[Bindable (false)]
[Browsable (false)]
public override string Text {
get { return base.Text; }
set { base.Text = value; }
}
[DefaultValue (1)]
public int TickFrequency {
get { return tickFrequency; }
set {
if ( value > 0 ) {
tickFrequency = value;
Refresh ();
}
}
}
[DefaultValue (TickStyle.BottomRight)]
public TickStyle TickStyle {
get { return tickStyle; }
set {
if (!Enum.IsDefined (typeof (TickStyle), value))
throw new InvalidEnumArgumentException (string.Format("Enum argument value '{0}' is not valid for TickStyle", value));
if (tickStyle != value) {
tickStyle = value;
Refresh ();
}
}
}
[DefaultValue (0)]
[Bindable (true)]
public int Value {
get { return position; }
set {
SetValue (value, false);
}
}
void SetValue (int value, bool fire_onscroll)
{
if (value < Minimum || value > Maximum)
throw new ArgumentException(
String.Format ("'{0}' is not a valid value for 'Value'. 'Value' should be between 'Minimum' and 'Maximum'", value));
if (position == value)
return;
position = value;
// OnScroll goes before OnValueChanged
if (fire_onscroll)
OnScroll (EventArgs.Empty);
// XXX any reason we don't call OnValueChanged here?
EventHandler eh = (EventHandler)(Events [ValueChangedEvent]);
if (eh != null)
eh (this, EventArgs.Empty);
Invalidate (thumb_area);
}
#endregion //Public Properties
#region Public Methods
public void BeginInit ()
{
}
protected override void CreateHandle ()
{
base.CreateHandle ();
}
protected override void SetBoundsCore (int x, int y,int width, int height, BoundsSpecified specified)
{
if (AutoSize) {
if (orientation == Orientation.Vertical) {
width = size_of_autosize;
} else {
height = size_of_autosize;
}
}
base.SetBoundsCore (x, y, width, height, specified);
}
public void EndInit ()
{
}
protected override bool IsInputKey (Keys keyData)
{
if ((keyData & Keys.Alt) == 0) {
switch (keyData & Keys.KeyCode) {
case Keys.Down:
case Keys.Right:
case Keys.Up:
case Keys.Left:
case Keys.PageUp:
case Keys.PageDown:
case Keys.Home:
case Keys.End:
return true;
}
}
return base.IsInputKey (keyData);
}
protected override void OnBackColorChanged (EventArgs e)
{
base.OnBackColorChanged (e);
}
protected override void OnHandleCreated (EventArgs e)
{
base.OnHandleCreated (e);
if (AutoSize)
if (Orientation == Orientation.Horizontal)
Size = new Size (Width, 40);
else
Size = new Size (50, Height);
UpdatePos (Value, true);
}
[EditorBrowsable (EditorBrowsableState.Advanced)]
protected override void OnMouseWheel (MouseEventArgs e)
{
base.OnMouseWheel (e);
if (!Enabled) return;
if (e.Delta > 0)
SmallDecrement ();
else
SmallIncrement ();
}
[EditorBrowsable (EditorBrowsableState.Advanced)]
protected virtual void OnRightToLeftLayoutChanged (EventArgs e)
{
EventHandler eh = (EventHandler)Events [RightToLeftLayoutChangedEvent];
if (eh != null)
eh (this, e);
}
protected virtual void OnScroll (EventArgs e)
{
EventHandler eh = (EventHandler)(Events [ScrollEvent]);
if (eh != null)
eh (this, e);
}
protected override void OnSystemColorsChanged (EventArgs e)
{
base.OnSystemColorsChanged (e);
Invalidate ();
}
protected virtual void OnValueChanged (EventArgs e)
{
EventHandler eh = (EventHandler)(Events [ValueChangedEvent]);
if (eh != null)
eh (this, e);
}
public void SetRange (int minValue, int maxValue)
{
Minimum = minValue;
Maximum = maxValue;
}
public override string ToString()
{
return string.Format("System.Windows.Forms.TrackBar, Minimum: {0}, Maximum: {1}, Value: {2}",
Minimum, Maximum, Value);
}
protected override void WndProc (ref Message m)
{
base.WndProc (ref m);
// Basically we want ControlStyles.ResizeRedraw but
// tests say we can't set that flag
if ((Msg)m.Msg == Msg.WM_WINDOWPOSCHANGED && Visible)
Invalidate ();
}
#endregion Public Methods
#region Private Methods
private void UpdatePos (int newPos, bool update_trumbpos)
{
if (newPos < minimum){
SetValue (minimum, true);
}
else {
if (newPos > maximum) {
SetValue (maximum, true);
}
else {
SetValue (newPos, true);
}
}
}
// Used by UIA implementation, so making internal
internal void LargeIncrement ()
{
UpdatePos (position + LargeChange, true);
Invalidate (thumb_area);
}
// Used by UIA implementation, so making internal
internal void LargeDecrement ()
{
UpdatePos (position - LargeChange, true);
Invalidate (thumb_area);
}
private void SmallIncrement ()
{
UpdatePos (position + SmallChange, true);
Invalidate (thumb_area);
}
private void SmallDecrement ()
{
UpdatePos (position - SmallChange, true);
Invalidate (thumb_area);
}
private void OnMouseUpTB (object sender, MouseEventArgs e)
{
if (!Enabled) return;
if (thumb_pressed == true || mouse_clickmove == true) {
thumb_pressed = false;
holdclick_timer.Enabled = false;
this.Capture = false;
Invalidate (thumb_area);
}
}
private void OnMouseDownTB (object sender, MouseEventArgs e)
{
if (!Enabled) return;
mouse_moved = false;
bool fire_timer = false;
Point point = new Point (e.X, e.Y);
if (orientation == Orientation.Horizontal) {
if (thumb_pos.Contains (point)) {
this.Capture = true;
thumb_pressed = true;
thumb_mouseclick = e.X;
mouse_down_x_offset = e.X - thumb_pos.X;
Invalidate (thumb_area);
}
else {
if (thumb_area.Contains (point)) {
is_moving_right = e.X > thumb_pos.X + thumb_pos.Width;
if (is_moving_right)
LargeIncrement ();
else
LargeDecrement ();
Invalidate (thumb_area);
fire_timer = true;
mouse_clickmove = true;
}
}
}
else {
Rectangle vertical_thumb_pos = thumb_pos;
vertical_thumb_pos.Width = thumb_pos.Height;
vertical_thumb_pos.Height = thumb_pos.Width;
if (vertical_thumb_pos.Contains (point)) {
this.Capture = true;
thumb_pressed = true;
thumb_mouseclick = e.Y;
mouse_down_x_offset = e.Y - thumb_pos.Y;
Invalidate (thumb_area);
}
else {
if (thumb_area.Contains (point)) {
is_moving_right = e.Y > thumb_pos.Y + thumb_pos.Width;
if (is_moving_right)
LargeDecrement ();
else
LargeIncrement ();
Invalidate (thumb_area);
fire_timer = true;
mouse_clickmove = true;
}
}
}
if (fire_timer) {
holdclick_timer.Interval = 300;
holdclick_timer.Enabled = true;
}
}
private void OnMouseMoveTB (object sender, MouseEventArgs e)
{
if (!Enabled) return;
mouse_moved = true;
/* Moving the thumb */
if (thumb_pressed)
SetValue (ThemeEngine.Current.TrackBarValueFromMousePosition (e.X, e.Y, this), true);
ThumbEntered = GetRealThumbRectangle ().Contains (e.Location);
}
Rectangle GetRealThumbRectangle ()
{
Rectangle result = thumb_pos;
if (Orientation == Orientation.Vertical) {
result.Width = thumb_pos.Height;
result.Height = thumb_pos.Width;
}
return result;
}
internal override void OnPaintInternal (PaintEventArgs pevent)
{
ThemeEngine.Current.DrawTrackBar (pevent.Graphics, pevent.ClipRectangle, this);
}
private void OnLostFocusTB (object sender, EventArgs e)
{
Invalidate();
}
private void OnGotFocusTB (object sender, EventArgs e)
{
Invalidate();
}
private void OnKeyDownTB (object sender, KeyEventArgs e)
{
bool horiz = Orientation == Orientation.Horizontal;
switch (e.KeyCode) {
case Keys.Down:
case Keys.Right:
if(horiz)
SmallIncrement();
else
SmallDecrement ();
break;
case Keys.Up:
case Keys.Left:
if (horiz)
SmallDecrement();
else
SmallIncrement();
break;
case Keys.PageUp:
if (horiz)
LargeDecrement();
else
LargeIncrement();
break;
case Keys.PageDown:
if (horiz)
LargeIncrement();
else
LargeDecrement();
break;
case Keys.Home:
if (horiz)
SetValue (Minimum, true);
else
SetValue (Maximum, true);
break;
case Keys.End:
if (horiz)
SetValue (Maximum, true);
else
SetValue (Minimum, true);
break;
default:
break;
}
}
private void OnFirstClickTimer (Object source, ElapsedEventArgs e)
{
Point pnt;
pnt = PointToClient (MousePosition);
/*
On Win32 the thumb only moves in one direction after a click,
if the thumb passes the clicked point it will never go in the
other way unless the mouse is released and clicked again. This
is also true if the mouse moves while beeing hold down.
*/
if (thumb_area.Contains (pnt)) {
bool invalidate = false;
if (orientation == Orientation.Horizontal) {
if (pnt.X > thumb_pos.X + thumb_pos.Width && is_moving_right) {
LargeIncrement ();
invalidate = true;
} else if (pnt.X < thumb_pos.X && !is_moving_right) {
LargeDecrement ();
invalidate = true;
}
} else {
if (pnt.Y > thumb_pos.Y + thumb_pos.Width && is_moving_right) {
LargeDecrement ();
invalidate = true;
} else if (pnt.Y < thumb_pos.Y && !is_moving_right) {
LargeIncrement ();
invalidate = true;
}
}
if (invalidate)
// A Refresh is necessary because the mouse is down and if we just invalidate
// we'll only get paint events once in a while.
Refresh();
}
}
void OnMouseLeave (object sender, EventArgs e)
{
ThumbEntered = false;
}
#endregion // Private Methods
}
}
|