ProgressBarEx.cs
上传用户:nnpulika
上传日期:2013-02-15
资源大小:597k
文件大小:61k
源码类别:

状态条

开发平台:

C#

  1. using System;
  2. using System.Collections;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Drawing.Drawing2D;
  6. using System.Data;
  7. using System.Windows.Forms;
  8. using System.Runtime.InteropServices;
  9. using System.Diagnostics;
  10. using UtilityLibrary.Win32;
  11. using UtilityLibrary.General;
  12. namespace UtilityLibrary.WinControls
  13. {
  14. #region Enumerations
  15. public enum ProgressBarProperty
  16. {
  17. BackgroundColor,
  18. ForegroundColor,
  19. BorderColor,
  20. Border3D,
  21. Enable3DBorder,
  22. Value,
  23. Step,
  24. Minimun,
  25. Maximun,
  26. Smooth,
  27. ShowProgressText,
  28. ProgressText,
  29. BackgroundBitmap,
  30. ForegroundBitmap,
  31. ProgressTextHiglightColor,
  32. ProgressTextColor,
  33. GradientStartColor,
  34. GradientMiddleColor,
  35. GradientEndColor,
  36.         WaitingGradientSize,
  37. WaitingSpeed,
  38. WaitingStep,
  39. Orientation
  40. }
  41. #endregion
  42.     
  43. #region Delegates
  44. // I put the delegate outside the class so that the user does not have
  45. // to prefix the progressbar class name to use this delegate
  46. // Putting them inside the class just make them hard to use
  47. // Declare the property change event signature
  48. public delegate void ProgressBarPropertyChangedHandler(ProgressBarEx pogressBar, ProgressBarProperty prop);
  49. #endregion
  50. /// <summary>
  51. /// Summary description for FlatProgressBar.
  52. /// </summary>
  53. [ToolboxItem(false)]
  54. public class ProgressBarEx : System.Windows.Forms.Control
  55. {
  56. #region Enumerations
  57. // We need to know how we are going to draw the progress bar
  58. // this won't come from the user setting as a flag but how the
  59. // progress bar is constructed
  60. private enum ProgressBarType 
  61. Standard, 
  62. Bitmap, 
  63. Gradient, 
  64. WaitingGradient,
  65. GradientTube,
  66. WaitingGradientTube
  67. }
  68. #endregion
  69. #region Events
  70. public event ProgressBarPropertyChangedHandler PropertyChanged;
  71. #endregion
  72. #region Class Variables
  73. // Standard progress bar
  74. Color backgroundColor;
  75. Color foregroundColor;
  76. Color borderColor;
  77. // Property backers
  78. int _value = 0;
  79. int step = 1;
  80. int min = 0;
  81. int max = 100;
  82. bool smooth = false;
  83. Border3DStyle border3D = Border3DStyle.Flat;
  84. bool enable3DBorder = false;
  85. // Text related
  86. bool showProgressText = false;
  87. string progressText = string.Empty;
  88. Color progressTextHiglightColor = Color.Empty;
  89. Color progressTextColor = Color.Empty;
  90. // Progress Bar type
  91. ProgressBarType barType = ProgressBarType.Standard;
  92. // Bitmap progress Bar
  93. Bitmap foregroundBitmap = null;
  94.         Bitmap backgroundBitmap = null;
  95. // Gradient progress bar
  96. Color gradientStartColor = Color.Empty;
  97. Color gradientMiddleColor = Color.Empty;
  98. Color gradientEndColor = Color.Empty;
  99. // Waiting progress bar
  100. System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
  101. int waitingGradientSize = 30;
  102. int waitingSpeed = 25;
  103. int waitingStep = 5;
  104. int waitingPos = 0;
  105. const int TUBE_WIDTH = 20;
  106. int tubeOffset = 0;
  107. // Gradient tube helpers
  108. Color lightColor = Color.Empty;
  109. Color lighterColor = Color.Empty;
  110. Color lightestColor = Color.Empty;
  111. Color darkColor = Color.Empty;
  112. Color darkerColor = Color.Empty;
  113. // Vertical/Horizontal progress bar
  114. Orientation orientation = Orientation.Horizontal;
  115. #endregion
  116.         
  117. #region Constructors
  118. // Default contructor to draw a "Standard" progress Bar
  119. public ProgressBarEx()
  120. {
  121. InitializeProgressControl(ProgressBarType.Standard, ColorUtil.VSNetControlColor, 
  122. ColorUtil.VSNetBorderColor, ColorUtil.VSNetBorderColor, null, null, Color.Empty, Color.Empty, Color.Empty);
  123. }
  124. public ProgressBarEx(Bitmap foregroundBitmap, Bitmap backgroundBitmap)
  125. {
  126. InitializeProgressControl(ProgressBarType.Bitmap, ColorUtil.VSNetControlColor, 
  127. ColorUtil.VSNetBorderColor, ColorUtil.VSNetBorderColor, 
  128. foregroundBitmap, backgroundBitmap, Color.Empty, Color.Empty, Color.Empty);
  129. }
  130. public ProgressBarEx(Bitmap foregroundBitmap)
  131. {
  132. InitializeProgressControl(ProgressBarType.Bitmap, ColorUtil.VSNetControlColor, 
  133. ColorUtil.VSNetBorderColor,ColorUtil.VSNetBorderColor, 
  134. foregroundBitmap, null, Color.Empty, Color.Empty, Color.Empty);
  135. }
  136. public ProgressBarEx(Color gradientStartColor)
  137. {
  138. InitializeProgressControl(ProgressBarType.GradientTube, ColorUtil.VSNetControlColor, 
  139. ColorUtil.VSNetBorderColor, ColorUtil.VSNetBorderColor, 
  140. foregroundBitmap, null, gradientStartColor, Color.Empty, Color.Empty);
  141. // Initialize helper colors
  142. InitializeGradientTubeColors(gradientStartColor);
  143.     }
  144. public ProgressBarEx(Color gradientStartColor, bool waiting)
  145. {
  146. ProgressBarType type = ProgressBarType.GradientTube;
  147. if ( waiting == true )
  148. {
  149. type = ProgressBarType.WaitingGradientTube;
  150. // Initialize timer callback
  151. timer.Tick += new EventHandler(OnWaitingTick);
  152. timer.Interval = waitingSpeed;
  153. }
  154. InitializeProgressControl(type, ColorUtil.VSNetControlColor, 
  155. ColorUtil.VSNetBorderColor, ColorUtil.VSNetBorderColor, 
  156. foregroundBitmap, null, gradientStartColor, Color.Empty, Color.Empty);
  157.             
  158. // Initialize helper colors
  159. InitializeGradientTubeColors(gradientStartColor);
  160. }
  161. public ProgressBarEx(Color gradientStartColor, Color gradientEndColor)
  162. {
  163. InitializeProgressControl(ProgressBarType.Gradient, ColorUtil.VSNetControlColor, 
  164. ColorUtil.VSNetBorderColor, ColorUtil.VSNetBorderColor, 
  165. foregroundBitmap, null, gradientStartColor, Color.Empty, gradientEndColor);
  166. }
  167. public ProgressBarEx(Color gradientStartColor, Color gradientEndColor, bool waiting)
  168. {
  169. ProgressBarType type = ProgressBarType.Gradient;
  170. if ( waiting == true )
  171. {
  172. type = ProgressBarType.WaitingGradient;
  173. // Initialize timer callback
  174. timer.Tick += new EventHandler(OnWaitingTick);
  175. timer.Interval = waitingSpeed;
  176. }
  177. InitializeProgressControl(type, ColorUtil.VSNetControlColor, 
  178. ColorUtil.VSNetBorderColor, ColorUtil.VSNetBorderColor, 
  179. foregroundBitmap, null, gradientStartColor, Color.Empty, gradientEndColor);
  180. }
  181. public ProgressBarEx(Color gradientStartColor, Color gradientMiddleColor, Color gradientEndColor)
  182. {
  183. InitializeProgressControl(ProgressBarType.Gradient, ColorUtil.VSNetControlColor, 
  184. ColorUtil.VSNetBorderColor, ColorUtil.VSNetBorderColor, 
  185. foregroundBitmap, null, gradientStartColor, gradientMiddleColor, gradientEndColor);
  186. }
  187. void InitializeProgressControl(ProgressBarType barType, Color backgroundColor, 
  188. Color foregroundColor, Color borderColor, Bitmap foregroundBitmap, Bitmap backgroundBitmap, Color gradientStartColor,
  189. Color gradientMiddleColor, Color gradientEndColor)
  190. {
  191. // Setup Double buffering 
  192. SetStyle(ControlStyles.ResizeRedraw 
  193. |ControlStyles.AllPaintingInWmPaint|ControlStyles.UserPaint|ControlStyles.DoubleBuffer, true);
  194. this.barType = barType;
  195. this.backgroundColor = backgroundColor;
  196. this.foregroundColor = foregroundColor;
  197. this.borderColor = borderColor;
  198. this.foregroundBitmap = foregroundBitmap;
  199. this.backgroundBitmap = backgroundBitmap;
  200. this.gradientStartColor = gradientStartColor;
  201. this.gradientMiddleColor = gradientMiddleColor;
  202. this.gradientEndColor = gradientEndColor;
  203. }
  204. #endregion
  205. #region Overrides
  206. protected override void OnPaint(PaintEventArgs e)
  207. {
  208. base.OnPaint(e);
  209. // Get window area
  210. Win32.RECT rc = new Win32.RECT();
  211. WindowsAPI.GetWindowRect(Handle, ref rc);
  212. // Convert to a client size rectangle
  213. Rectangle rect = new Rectangle(0, 0, rc.right - rc.left, rc.bottom - rc.top);
  214. Graphics g = e.Graphics;
  215. Rectangle workRect = WorkRect;
  216. DrawBackground(g, workRect);
  217. DrawBorder(g, rect);
  218. if ( _value != 0 )
  219. DrawForeground(g, workRect);
  220. }
  221. protected override void OnHandleCreated(EventArgs e)
  222. {
  223. base.OnHandleCreated(e);
  224. // Initialize waitingPos
  225. Rectangle rc = ClientRectangle;
  226. if ( orientation == Orientation.Horizontal )
  227.                 waitingPos = rc.Width/2;
  228. else
  229. waitingPos = rc.Height/2;
  230. }
  231. #endregion
  232. #region Properties
  233. public Color BackgroundColor
  234. set 
  235. if ( backgroundColor != value )
  236. {
  237. backgroundColor = value;
  238. FirePropertyChange(ProgressBarProperty.BackgroundColor);
  239. }
  240. }
  241. get { return backgroundColor; }
  242. }
  243. public Color ForegroundColor
  244. set 
  245. if ( foregroundColor != value )
  246. {
  247. foregroundColor = value;
  248. FirePropertyChange(ProgressBarProperty.ForegroundColor);
  249. }
  250. }
  251. get { return foregroundColor; }
  252. }
  253. public Color BorderColor
  254. set 
  255. if ( borderColor != value )
  256. {
  257. borderColor = value;
  258. FirePropertyChange(ProgressBarProperty.BorderColor);
  259. }
  260. }
  261. get { return borderColor; }
  262. }
  263. public int Value
  264. set
  265. if ( _value != value )
  266. {
  267. if ( !(value <= max && value >= min) )
  268. {
  269. // Throw exception to indicate out of range condition
  270. string message = "ProgressBarEx Value: " + value.ToString() 
  271. + " is out of range. It needs to be between " +
  272. min.ToString() + " and " + max.ToString();
  273. ArgumentOutOfRangeException outRangeException = new ArgumentOutOfRangeException("Value", message);
  274. throw(outRangeException);
  275. }
  276. _value = value; 
  277. FirePropertyChange(ProgressBarProperty.Value);
  278. }
  279. }
  280. get { return _value; }
  281. }
  282. public new Size Size
  283. set 
  284. // Make sure width and height dimensions are always
  285. // an even number so that we can do round math
  286. //  when we draw the progress bar segments
  287. Size newSize = value;
  288. if ( newSize.Width % 2 != 0) newSize.Width++;
  289. if ( newSize.Height % 2 != 0) newSize.Height++;
  290. base.Size = newSize;
  291. }
  292. get { return base.Size; }
  293. }
  294. public int Step
  295. set 
  296. if ( step != value )
  297. {
  298. step = value;
  299. FirePropertyChange(ProgressBarProperty.Step);
  300. }
  301. }
  302. get { return step; }
  303. }
  304. public int Minimum
  305. set 
  306. if ( min != value )
  307. {
  308. if ( value >= max )
  309. {
  310. // Throw exception to indicate out of range condition
  311. string message = "ProgressBarEx Minimum Value: " 
  312. + value.ToString() + " is out of range. It needs to be less than " +
  313. "Maximun value: " + max.ToString();
  314. ArgumentOutOfRangeException outRangeException = new ArgumentOutOfRangeException("Value", message);
  315. throw(outRangeException);
  316. }
  317. min = value;
  318. FirePropertyChange(ProgressBarProperty.Minimun);
  319. }
  320. }
  321. get { return min; }
  322. }
  323. public int Maximum
  324. set 
  325. {
  326. if ( max != value )
  327. {
  328. if ( value <= min )
  329. {
  330. // Throw exception to indicate out of range condition
  331. string message = "ProgressBarEx Maximum Value: " + value.ToString() 
  332. + " is out of range. It needs to be greater than " +
  333. "Minimum value: " + min.ToString();
  334. ArgumentOutOfRangeException outRangeException = new ArgumentOutOfRangeException("Value", message);
  335. throw(outRangeException);
  336. }
  337. max = value;
  338. FirePropertyChange(ProgressBarProperty.Maximun);
  339. }
  340. }
  341. get { return max; }
  342. }
  343. public bool Smooth
  344. {
  345. set 
  346. {
  347. if ( smooth != value )
  348. {
  349. smooth = value;
  350. FirePropertyChange(ProgressBarProperty.Smooth);
  351. }
  352. }
  353. get { return smooth; }
  354. }
  355. public Border3DStyle Border3D
  356. {
  357. set 
  358. {
  359. if ( border3D != value )
  360. {
  361. border3D = value;
  362. FirePropertyChange(ProgressBarProperty.Border3D);
  363. }
  364. }
  365. get { return border3D; }
  366. }
  367. public bool Enable3DBorder
  368. {
  369. set 
  370. {
  371. if ( enable3DBorder != value )
  372. {
  373. enable3DBorder = value;
  374. FirePropertyChange(ProgressBarProperty.Enable3DBorder);
  375. }
  376. }
  377. get { return enable3DBorder; }
  378. }
  379. public bool ShowProgressText
  380. {
  381. set 
  382. {
  383. if ( showProgressText != value )
  384. {
  385. showProgressText = value;
  386. FirePropertyChange(ProgressBarProperty.ShowProgressText);
  387. }
  388. }
  389. get { return showProgressText; }
  390. }
  391. public string ProgressText
  392. {
  393. set 
  394. {
  395. if ( progressText != value )
  396. {
  397. progressText = value;
  398. FirePropertyChange(ProgressBarProperty.ProgressText);
  399. }
  400. }
  401. get { return progressText; }
  402. }
  403. public Color ProgressTextHiglightColor
  404. {
  405. set 
  406. {
  407. if ( progressTextHiglightColor != value )
  408. {
  409. progressTextHiglightColor = value;
  410. FirePropertyChange(ProgressBarProperty.ProgressTextHiglightColor);
  411. }
  412. }
  413. get { return progressTextHiglightColor; }
  414. }
  415. public Color ProgressTextColor
  416. {
  417. set 
  418. {
  419. if ( progressTextColor != value )
  420. {
  421. progressTextColor = value;
  422. FirePropertyChange(ProgressBarProperty.ProgressTextColor);
  423. }
  424. }
  425. get { return progressTextColor; }
  426. }
  427. public Bitmap ForegroundBitmap
  428. {
  429. set 
  430. {
  431. if ( foregroundBitmap != value )
  432. {
  433. foregroundBitmap = value;
  434. FirePropertyChange(ProgressBarProperty.ForegroundBitmap);
  435. }
  436. }
  437. get { return foregroundBitmap; }
  438. }
  439. public Bitmap BackgroundBitmap
  440. {
  441. set 
  442. {
  443. if ( backgroundBitmap != value )
  444. {
  445. backgroundBitmap = value;
  446. FirePropertyChange(ProgressBarProperty.BackgroundBitmap);
  447. }
  448. }
  449. get { return backgroundBitmap; }
  450. }
  451. public Color GradientStartColor
  452. {
  453. set 
  454. {
  455. if ( gradientStartColor != value )
  456. {
  457. gradientStartColor = value;
  458. if ( barType == ProgressBarType.GradientTube || barType == ProgressBarType.WaitingGradientTube )
  459. InitializeGradientTubeColors(value);
  460. FirePropertyChange(ProgressBarProperty.GradientStartColor);
  461. }
  462. }
  463. get { return gradientStartColor; }
  464. }
  465. public Color GradientMiddleColor
  466. {
  467. set 
  468. {
  469. if ( gradientMiddleColor != value )
  470. {
  471. gradientMiddleColor = value;
  472. FirePropertyChange(ProgressBarProperty.GradientMiddleColor);
  473. }
  474. }
  475. get { return gradientMiddleColor; }
  476. }
  477. public Color GradientEndColor
  478. {
  479. set 
  480. {
  481. if ( gradientEndColor != value )
  482. {
  483. gradientEndColor = value;
  484. FirePropertyChange(ProgressBarProperty.GradientEndColor);
  485. }
  486. }
  487. get { return gradientEndColor; }
  488. }
  489. public int WaitingGradientSize
  490. {
  491. set 
  492. {
  493. if ( waitingGradientSize != value )
  494. {
  495. waitingGradientSize = value;
  496. // Keep the size between 0 and 100
  497. if ( waitingGradientSize < 0 )
  498. waitingGradientSize = 10;
  499. else if ( waitingGradientSize > 100 )
  500. waitingGradientSize = 80;
  501. FirePropertyChange(ProgressBarProperty.WaitingGradientSize);
  502. }
  503. }
  504. get { return waitingGradientSize; }
  505. }
  506. public int WaitingSpeed
  507. {
  508. set 
  509. {
  510. if ( waitingSpeed != value )
  511. {
  512. bool timerEnabled = timer.Enabled;
  513. if ( timerEnabled )
  514. timer.Stop();
  515. waitingSpeed = value;
  516. timer.Interval = value;
  517. FirePropertyChange(ProgressBarProperty.WaitingSpeed);
  518. if ( timerEnabled )
  519.                         timer.Start();
  520. }
  521. }
  522. get { return waitingSpeed; }
  523. }
  524. public int WaitingStep
  525. {
  526. set 
  527. {
  528. if ( waitingStep != value )
  529. {
  530. waitingStep = value;
  531. FirePropertyChange(ProgressBarProperty.WaitingStep);
  532. }
  533. }
  534. get { return waitingStep; }
  535. }
  536. public Orientation Orientation
  537. {
  538. set 
  539. {
  540. if ( orientation != value )
  541. {
  542. orientation = value;
  543. FirePropertyChange(ProgressBarProperty.Orientation);
  544. }
  545. }
  546. get { return orientation; }
  547. }
  548. #endregion
  549. #region Methods
  550. public void PerformStep()
  551. {
  552. if ( _value < max )
  553. _value += step;
  554. if ( _value > max )
  555. _value = max;
  556. FirePropertyChange(ProgressBarProperty.Step);
  557. }
  558. public void StartWaiting()
  559. {
  560. // Only if we have a waiting progress bar
  561. if ( barType != ProgressBarType.WaitingGradient && barType !=  ProgressBarType.WaitingGradientTube )
  562. return;
  563.             timer.Start();
  564. }
  565. public void StopWaiting()
  566. {
  567. // Only if we have a waiting progress bar
  568. if ( barType != ProgressBarType.WaitingGradient && barType !=  ProgressBarType.WaitingGradientTube )
  569. return;
  570. timer.Stop();
  571. }
  572. #endregion
  573. #region Implementation
  574. // Methods
  575. void FirePropertyChange(ProgressBarProperty property)
  576. {
  577. // Fire event if we need to
  578. if (PropertyChanged != null)
  579. PropertyChanged(this, property);
  580. // Force a repaint of the control
  581. Invalidate();
  582. }
  583. void DrawBorder(Graphics g, Rectangle windowRect)
  584. {
  585. if ( enable3DBorder == false )
  586. {
  587. using ( Pen p = new Pen(borderColor) )
  588. {
  589. g.DrawRectangle(p, windowRect.Left, windowRect.Top,
  590. windowRect.Width-1, windowRect.Height-1);
  591. }
  592. }
  593. else 
  594. {
  595. ControlPaint.DrawBorder3D(g, windowRect, border3D);
  596. }
  597. }
  598. void DrawBackground(Graphics g, Rectangle workRect)
  599. {
  600. if ( barType == ProgressBarType.Standard )
  601. {
  602. DrawStandardBackground(g, workRect);
  603. }
  604. else if ( barType == ProgressBarType.Bitmap ) 
  605. {
  606. DrawBitmapBackground(g, workRect);
  607. }
  608. else if ( barType == ProgressBarType.Gradient )
  609. {
  610. DrawGradientBackground(g, workRect);
  611. }
  612. else if ( barType == ProgressBarType.GradientTube || barType == ProgressBarType.WaitingGradientTube )
  613. {
  614. DrawGradientTubeBackground(g, workRect);
  615. }
  616. }
  617. void DrawStandardBackground(Graphics g, Rectangle workRect)
  618. {
  619. using ( Brush b = new SolidBrush(backgroundColor) )
  620. {
  621. g.FillRectangle(b, workRect);
  622. }
  623. }
  624. void DrawBitmapBackground(Graphics g, Rectangle workRect)
  625. {
  626. if (  backgroundBitmap != null )
  627. {
  628. // If we strech the bitmap most likely than not the bitmap
  629. // won't look good. I will draw the background bitmap just 
  630. // by sampling a portion of the bitmap equal to the segment width
  631. // -- if we were drawing segments --- and draw this over and over
  632. // without leaving gaps
  633. if ( orientation == Orientation.Horizontal )
  634. {
  635. int segmentWidth = (workRect.Height)*3/4;
  636. segmentWidth -= 2;
  637. Rectangle drawingRect = new Rectangle(workRect.Left, workRect.Top, segmentWidth, workRect.Height);
  638. for ( int i = 0; i < workRect.Width; i += segmentWidth) 
  639. {
  640. g.DrawImage(backgroundBitmap, drawingRect.Left + i, drawingRect.Top,
  641. segmentWidth, workRect.Height);
  642. // If last segment does not fit, just draw a portion of it
  643. if ( i + segmentWidth > workRect.Width )
  644. g.DrawImage(backgroundBitmap, drawingRect.Left + i + segmentWidth, drawingRect.Top,
  645. workRect.Width - (drawingRect.Left + i + segmentWidth), workRect.Height);
  646. }
  647. }
  648. else
  649. {
  650. int segmentHeight = (workRect.Width)*3/4;
  651. segmentHeight -= 2;
  652. Rectangle drawingRect = new Rectangle(workRect.Left, workRect.Top, workRect.Width, segmentHeight);
  653. for ( int i = 0; i < workRect.Height; i += segmentHeight) 
  654. {
  655. g.DrawImage(backgroundBitmap, drawingRect.Left, drawingRect.Top + i,
  656. workRect.Width, segmentHeight);
  657. // If last segment does not fit, just draw a portion of it
  658. if ( i + segmentHeight > workRect.Height )
  659. g.DrawImage(backgroundBitmap, drawingRect.Left, drawingRect.Top + i + segmentHeight, workRect.Width,
  660. workRect.Height - (drawingRect.Top + i + segmentHeight));
  661. }
  662. }
  663. }
  664. else 
  665. {
  666. g.FillRectangle(new SolidBrush(backgroundColor), workRect);
  667. }
  668. }
  669. void DrawGradientBackground(Graphics g, Rectangle workRect)
  670. {
  671. // Same as the standard background
  672. using ( Brush b = new SolidBrush(backgroundColor) )
  673. {
  674. g.FillRectangle(b, workRect);
  675. }
  676. }
  677. void DrawGradientTubeBackground(Graphics g, Rectangle workRect)
  678. {
  679. // Draw background using a lighter shade of the gradientStartColor
  680. using ( Brush b = new SolidBrush(lightestColor) )
  681. {
  682. g.FillRectangle(b, workRect);
  683. }
  684. }
  685. void DrawForeground(Graphics g, Rectangle workRect)
  686. {
  687. if ( barType == ProgressBarType.Standard )
  688. {
  689. DrawStandardForeground(g, workRect);
  690. }
  691. else if ( barType == ProgressBarType.Bitmap ) 
  692. {
  693. DrawBitmapForeground(g, workRect);
  694. }
  695. else if ( barType == ProgressBarType.Gradient )
  696. {
  697. DrawGradientForeground(g, workRect);
  698. }
  699. else if ( barType == ProgressBarType.WaitingGradient )
  700. {
  701. DrawWaitingGradientForeground(g, workRect);
  702. }
  703. else if ( barType == ProgressBarType.GradientTube )
  704. {
  705. DrawGradientTubeForeground(g, workRect);
  706. }
  707. else if ( barType == ProgressBarType.WaitingGradientTube )
  708. {
  709. DrawWaitingGradientTubeForeground(g, workRect);
  710. }
  711. }
  712. void DrawStandardForeground(Graphics g, Rectangle workRect)
  713. {
  714. if ( smooth )
  715. DrawStandardForegroundSmooth(g, workRect);
  716. else
  717. DrawStandardForegroundSegmented(g, workRect);
  718. }
  719. void DrawBitmapForeground(Graphics g, Rectangle workRect)
  720. {
  721. if ( orientation == Orientation.Horizontal )
  722. {
  723. // We should have a valid foreground bitmap if the type of
  724. // the progress bar is bitmap
  725. Debug.Assert(foregroundBitmap != null);
  726. // If we strech the bitmap most likely than not the bitmap
  727. // won't look good. I will draw the foreground bitmap just 
  728. // by sampling a portion of the bitmap equal to the segment width
  729. // -- if we were drawing segments --- and draw this over and over
  730. // without leaving gaps
  731. int segmentWidth = (workRect.Height)*3/4;
  732. segmentWidth -= 2;
  733. int segmentTopGap = 1;
  734. int segmentLeftGap = 2;
  735. if ( smooth )
  736. segmentLeftGap = 0;
  737.                         
  738. Rectangle segmentRect = new Rectangle(workRect.Left, 
  739. workRect.Top, segmentWidth, workRect.Height);
  740.    
  741. int progressWidth = (GetScaledValue());
  742. if ( progressWidth < 0 ) progressWidth = 0;
  743. for ( int i = 0; i < progressWidth; i += segmentRect.Width+segmentLeftGap )
  744. {
  745. if ( i+segmentRect.Width+segmentLeftGap > progressWidth 
  746. && (i+segmentRect.Width+segmentLeftGap > WorkRect.Width) ) 
  747. {
  748. // if we are about to leave because next segment does not fit
  749. // draw the portion that fits
  750. int partialWidth = progressWidth-i;
  751. Rectangle drawingRect = new Rectangle(segmentRect.Left+i, 
  752. segmentRect.Top+segmentTopGap, partialWidth, segmentRect.Height-(segmentTopGap*2));
  753. g.DrawImage(foregroundBitmap, drawingRect, 0, 0, drawingRect.Width, drawingRect.Height, GraphicsUnit.Pixel);
  754. break;
  755. }
  756. Rectangle completeSegment = new Rectangle(segmentRect.Left+i, segmentRect.Top+segmentTopGap, 
  757. segmentRect.Width, segmentRect.Height-(segmentTopGap*2));
  758. g.DrawImage(foregroundBitmap, completeSegment, 0, 0, 
  759. completeSegment.Width, completeSegment.Height, GraphicsUnit.Pixel);
  760. }
  761. }
  762. else
  763. {
  764. // We should have a valid foreground bitmap if the type of
  765. // the progress bar is bitmap
  766. Debug.Assert(foregroundBitmap != null);
  767. // If we strech the bitmap most likely than not the bitmap
  768. // won't look good. I will draw the foreground bitmap just 
  769. // by sampling a portion of the bitmap equal to the segment width
  770. // -- if we were drawing segments --- and draw this over and over
  771. // without leaving gaps
  772. int segmentHeight = (workRect.Width)*3/4;
  773. segmentHeight -= 2;
  774. int segmentTopGap = 2;
  775. int segmentLeftGap = 1;
  776. if ( smooth )
  777. segmentTopGap = 0;
  778.                         
  779. Rectangle segmentRect = new Rectangle(workRect.Left, 
  780. workRect.Top, workRect.Width, segmentHeight);
  781.    
  782. int progressHeight = (GetScaledValue());
  783. if ( progressHeight < 0 ) progressHeight = 0;
  784. for ( int i = 0; i < progressHeight; i += segmentRect.Height+segmentTopGap )
  785. {
  786. int top = (workRect.Bottom - segmentRect.Height) - i;
  787. if ( top < workRect.Top ) 
  788. {
  789. // if we are about to leave because next segment does not fit
  790. // draw the portion that fits
  791. int partialHeight = progressHeight-i;
  792. Rectangle drawingRect = new Rectangle(segmentRect.Left+segmentLeftGap, 
  793. workRect.Top, segmentRect.Width-(segmentLeftGap*2), partialHeight);
  794. g.DrawImage(foregroundBitmap, drawingRect, 0, 0, drawingRect.Width, drawingRect.Height, GraphicsUnit.Pixel);
  795. break;
  796. }
  797. Rectangle completeSegment = new Rectangle(segmentRect.Left+segmentLeftGap, top, 
  798. segmentRect.Width-(segmentLeftGap*2), segmentRect.Height);
  799. g.DrawImage(foregroundBitmap, completeSegment, 0, 0, 
  800. completeSegment.Width, completeSegment.Height, GraphicsUnit.Pixel);
  801. }
  802. }
  803. }
  804.         void DrawGradientForeground(Graphics g, Rectangle workRect)
  805. {
  806. // Three color gradient?
  807. bool useMiddleColor = false;
  808. if ( gradientMiddleColor != Color.Empty )
  809. useMiddleColor = true;
  810. if ( useMiddleColor )
  811. DrawThreeColorsGradient(g, workRect);
  812. else
  813. DrawTwoColorsGradient(g, workRect);
  814. }
  815. void DrawWaitingGradientForeground(Graphics g, Rectangle workRect)
  816. {
  817. if ( orientation == Orientation.Horizontal )
  818. DrawWaitingGradientForegroundHorizontal(g, workRect);
  819. else
  820. DrawWaitingGradientForegroundVertical(g, workRect);
  821. }
  822. void DrawWaitingGradientForegroundHorizontal(Graphics g, Rectangle workRect)
  823. {
  824. Rectangle rc = workRect;
  825. Region oldRegion = g.Clip;
  826. g.Clip = new Region(rc);
  827. // Boolean helpers
  828. bool useLeftBrush = false;
  829. bool useRightBrush = false;
  830. // Initialize rectangles
  831. Rectangle left = rc;
  832. Rectangle right = rc;
  833. Rectangle leftFill = rc;
  834. Rectangle rightFill = rc;
  835. Rectangle partialLeft = rc;
  836. Rectangle partialRight = rc;
  837. int gradientSize = (int)((float)(waitingGradientSize/2)*((float)rc.Width/100));
  838.             
  839. // Adjust rectangles using waiting bar type settings
  840. left.Width = gradientSize;
  841. left.X = waitingPos - gradientSize;
  842. right.X = waitingPos;
  843. right.Width = gradientSize;
  844. leftFill.Width = waitingPos - gradientSize;
  845. rightFill.X = waitingPos + gradientSize;
  846. rightFill.Width = ClientRectangle.Width - (waitingPos + gradientSize);
  847. if ( (waitingPos + gradientSize) > rc.Width )
  848. {
  849. useRightBrush = true;
  850. partialRight.X = -(rc.Width - waitingPos + rc.Left);
  851. partialRight.Width = gradientSize;
  852. leftFill.X = partialRight.X + gradientSize;
  853. leftFill.Width -= (partialRight.X + gradientSize);
  854. }
  855. if ( waitingPos < gradientSize )
  856. {
  857. useLeftBrush = true;
  858. partialLeft.X = (rc.Width - gradientSize) + waitingPos;
  859. partialLeft.Width = gradientSize;
  860. rightFill.X = right.X + gradientSize;
  861. rightFill.Width = partialLeft.X - rightFill.X;
  862. }
  863. // Paint partial right rectangle
  864. if ( useRightBrush )
  865. {
  866. using ( Brush b = new LinearGradientBrush(partialRight, gradientEndColor, gradientStartColor, 0, true) )
  867. {
  868. g.FillRectangle(b, partialRight);
  869. // There is a bug in the LinearGradientBrush logic
  870. // that causes the first line in the gradient to use the EndColor of the gradient 
  871. // instead of using the StartColor of the gradient
  872. // To compensate, draw a one pixel wide line using the start color
  873. using ( Pen p = new Pen(gradientEndColor) )
  874. {
  875. g.DrawLine(p, partialRight.Left, partialRight.Top, partialRight.Left, partialRight.Bottom);
  876. }
  877. }
  878. }
  879. // Partial left rectangle
  880. if ( useLeftBrush )
  881. {
  882. using ( Brush b = new LinearGradientBrush(partialLeft, gradientStartColor, gradientEndColor, 0, true) )
  883. {
  884. g.FillRectangle(b, partialLeft);
  885. // Same bug fix as above
  886. using ( Pen p = new Pen(gradientStartColor) )
  887. {
  888. g.DrawLine(p, partialLeft.Left, partialLeft.Top, partialLeft.Left, partialLeft.Bottom);
  889. }
  890. }
  891. }
  892. // Paint left fill rectangle
  893. using ( Brush b = new SolidBrush(gradientStartColor) )
  894. {
  895. g.FillRectangle(b, leftFill);
  896. }
  897. // Paint left rectangle
  898. if ( left.Width > 0 )
  899. {
  900. using ( Brush b = new LinearGradientBrush(left, gradientStartColor, gradientEndColor, LinearGradientMode.Horizontal) )
  901. {
  902. g.FillRectangle(b, left);
  903. // Same bug fix as above
  904. using ( Pen p = new Pen(gradientStartColor) )
  905. {
  906. g.DrawLine(p, left.Left, left.Top, left.Left, left.Bottom);
  907. }
  908. }
  909. }
  910. // Paint right rectangle
  911. if ( right.Width > 0 )
  912. {
  913. using ( Brush b = new LinearGradientBrush(right, gradientEndColor, gradientStartColor, 0, true) )
  914. {
  915. g.FillRectangle(b, right);
  916. // Same bug fix as above
  917. using ( Pen p = new Pen(gradientEndColor) )
  918. {
  919. g.DrawLine(p, right.Left, right.Top, right.Left, right.Bottom);
  920. }
  921. }
  922. }
  923. // Paint right fill rectangle
  924. using ( Brush b = new SolidBrush(gradientStartColor) )
  925. {
  926. g.FillRectangle(b, rightFill);
  927. }
  928. // Put back old region
  929. g.Clip = oldRegion;
  930. }
  931. void DrawWaitingGradientForegroundVertical(Graphics g, Rectangle workRect)
  932. {
  933. Rectangle rc = workRect;
  934. Region oldRegion = g.Clip;
  935. g.Clip = new Region(rc);
  936. // Boolean helpers
  937. bool useLeftBrush = false;
  938. bool useRightBrush = false;
  939. // Initialize rectangles
  940. Rectangle left = rc;
  941. Rectangle right = rc;
  942. Rectangle leftFill = rc;
  943. Rectangle rightFill = rc;
  944. Rectangle partialLeft = rc;
  945. Rectangle partialRight = rc;
  946. int gradientSize = (int)((float)(waitingGradientSize/2)*((float)rc.Height/100));
  947.             
  948. // Adjust rectangles using waiting bar type settings
  949. left.Height = gradientSize;
  950. left.Y = waitingPos;
  951. right.Y = waitingPos - gradientSize;
  952. right.Height = gradientSize;
  953. leftFill.Y = waitingPos + gradientSize;
  954. leftFill.Height = rc.Bottom - (waitingPos + gradientSize);
  955. rightFill.Y = rc.Top;
  956. rightFill.Height = right.Y - rc.Top;
  957. if ( (waitingPos - gradientSize) < rc.Top )
  958. {
  959. useRightBrush = true;
  960. partialRight.Y = rc.Bottom - (gradientSize - waitingPos);
  961. partialRight.Height = gradientSize;
  962. leftFill.Height -= (gradientSize - waitingPos);
  963. }
  964. if ( waitingPos + gradientSize > rc.Bottom )
  965. {
  966. useLeftBrush = true;
  967. partialLeft.Y = rc.Top - (rc.Bottom - waitingPos);
  968. partialLeft.Height = gradientSize;
  969. rightFill.Height -=  gradientSize - (rc.Bottom - waitingPos);
  970. rightFill.Y = right.Y - rightFill.Height;
  971. }
  972. // Paint partial right rectangle
  973. if ( useRightBrush )
  974. {
  975. using ( Brush b = new LinearGradientBrush(partialRight, gradientStartColor, gradientEndColor, LinearGradientMode.Vertical) )
  976. {
  977. g.FillRectangle(b, partialRight);
  978. // To fix bug
  979. using ( Pen p = new Pen(gradientStartColor) )
  980. {
  981. g.DrawLine(p, partialRight.Left, partialRight.Top, partialRight.Right, partialRight.Top);
  982. }
  983. }
  984. }
  985. // Partial left rectangle
  986. if ( useLeftBrush )
  987. {
  988. using ( Brush b = new LinearGradientBrush(partialLeft, gradientEndColor, gradientStartColor, LinearGradientMode.Vertical) )
  989. {
  990. g.FillRectangle(b, partialLeft);
  991. // To fix bug
  992. using ( Pen p = new Pen(gradientEndColor) )
  993. {
  994. g.DrawLine(p, partialLeft.Left, partialLeft.Top, partialLeft.Right, partialLeft.Top);
  995. }
  996. }
  997. }
  998. // Paint left fill rectangle
  999. using ( Brush b = new SolidBrush(gradientStartColor) )
  1000. {
  1001. g.FillRectangle(b, leftFill);
  1002. }
  1003. // Paint left rectangle
  1004. if ( left.Width > 0 )
  1005. {
  1006. using ( Brush b = new LinearGradientBrush(left, gradientEndColor, gradientStartColor, LinearGradientMode.Vertical) )
  1007. {
  1008. g.FillRectangle(b, left);
  1009. }
  1010. // To fix bug
  1011. using ( Pen p = new Pen(gradientEndColor) )
  1012. {
  1013. g.DrawLine(p, left.Left, left.Top, left.Right, left.Top);
  1014. }
  1015. }
  1016. // Paint right rectangle
  1017. if ( right.Width > 0 )
  1018. {
  1019. using ( Brush b = new LinearGradientBrush(right, gradientStartColor, gradientEndColor, LinearGradientMode.Vertical) )
  1020. {
  1021. g.FillRectangle(b, right);
  1022. }
  1023. // To fix bug
  1024. using ( Pen p = new Pen(gradientStartColor) )
  1025. {
  1026. g.DrawLine(p, right.Left, right.Top, right.Right, right.Top);
  1027. }
  1028. }
  1029. // Paint right fill rectangle
  1030. using ( Brush b = new SolidBrush(gradientStartColor) )
  1031. {
  1032. g.FillRectangle(b, rightFill);
  1033. }
  1034. // Put back old region
  1035. g.Clip = oldRegion;
  1036. }
  1037. void DrawGradientTubeForeground(Graphics g, Rectangle workRect)
  1038. {
  1039. Pen colorPen = new Pen(gradientStartColor);
  1040. Pen lightPen = new Pen(lightColor);
  1041. Pen lighterPen = new Pen(lighterColor);
  1042. Pen darkPen = new Pen(darkColor);
  1043. Pen darkerPen = new Pen(darkerColor);
  1044. int _value = GetScaledValue();
  1045. Rectangle rc = Rectangle.Empty;
  1046. if ( orientation == Orientation.Horizontal )
  1047. {
  1048. rc = new Rectangle(workRect.Left, workRect.Top, _value, workRect.Height);
  1049. // Set pixels
  1050. IntPtr hDC = g.GetHdc();
  1051. WindowsAPI.SetPixel(hDC, rc.Left+1, rc.Top+1, 
  1052. ColorUtil.RGB(lightColor.R, lightColor.G, lightColor.B));
  1053. WindowsAPI.SetPixel(hDC, rc.Left+1, rc.Bottom-3, 
  1054. ColorUtil.RGB(lightColor.R, lightColor.G, lightColor.B));
  1055. WindowsAPI.SetPixel(hDC, rc.Left+1, rc.Top+2, 
  1056. ColorUtil.RGB(lighterColor.R, lighterColor.G, lighterColor.B));
  1057. WindowsAPI.SetPixel(hDC, rc.Left+1, rc.Bottom-4, 
  1058. ColorUtil.RGB(lighterColor.R, lighterColor.G, lighterColor.B));
  1059. WindowsAPI.SetPixel(hDC, rc.Left+1, rc.Top, 
  1060. ColorUtil.RGB(gradientStartColor.R, gradientStartColor.G, gradientStartColor.B));
  1061. WindowsAPI.SetPixel(hDC, rc.Left+1, rc.Bottom-2, 
  1062. ColorUtil.RGB(gradientStartColor.R, gradientStartColor.G, gradientStartColor.B));
  1063. WindowsAPI.SetPixel(hDC, rc.Left+1, rc.Bottom-1, 
  1064. ColorUtil.RGB(darkColor.R, darkColor.G, darkColor.B));
  1065.             
  1066. g.ReleaseHdc(hDC);
  1067. // Draw regular color lines
  1068. g.DrawLine(lighterPen, rc.Left+2, rc.Top+3, rc.Right-3, rc.Top+3);
  1069. g.DrawLine(lighterPen, rc.Left+2, rc.Bottom-5, rc.Right-3, rc.Bottom-5);
  1070. g.DrawLine(lighterPen, rc.Right-3, rc.Top+3, rc.Right-3, rc.Bottom-5);
  1071. g.DrawLine(lightPen, rc.Left+2, rc.Top+2, rc.Right-3, rc.Top+2);
  1072. g.DrawLine(lightPen, rc.Left+2, rc.Bottom-4, rc.Right-3, rc.Bottom-4);
  1073. g.DrawLine(lightPen, rc.Left, rc.Top, rc.Left, rc.Bottom-1);
  1074. g.DrawLine(colorPen, rc.Left+2, rc.Top+1, rc.Right-2, rc.Top+1);
  1075. g.DrawLine(colorPen, rc.Left+2, rc.Bottom-3, rc.Right-3, rc.Bottom-3);
  1076. g.DrawLine(darkPen, rc.Left+2, rc.Bottom-2, rc.Right-3, rc.Bottom-2);
  1077. g.DrawLine(darkPen, rc.Right-2, rc.Top+2, rc.Right-2, rc.Bottom-2);
  1078. g.DrawLine(darkPen, rc.Left+2, rc.Top, rc.Right-1, rc.Top);
  1079. g.DrawLine(darkerPen, rc.Left+2, rc.Bottom-1, rc.Right-2, rc.Bottom-1);
  1080. g.DrawLine(darkerPen, rc.Right-1, rc.Top+1, rc.Right-1, rc.Bottom-1);
  1081. }
  1082. else
  1083. {
  1084. int top = workRect.Top + workRect.Height - _value;
  1085. rc = new Rectangle(workRect.Left, top, workRect.Width, _value);
  1086. // Set pixels
  1087. IntPtr hDC = g.GetHdc();
  1088. WindowsAPI.SetPixel(hDC, rc.Left, rc.Top+1, 
  1089. ColorUtil.RGB(gradientStartColor.R, 
  1090. gradientStartColor.G, gradientStartColor.B));
  1091. WindowsAPI.SetPixel(hDC, rc.Right-2, rc.Top+1, 
  1092. ColorUtil.RGB(gradientStartColor.R, 
  1093. gradientStartColor.G, gradientStartColor.B));
  1094. WindowsAPI.SetPixel(hDC, rc.Left+1, rc.Top+1, 
  1095. ColorUtil.RGB(lightColor.R, 
  1096. lightColor.G, lightColor.B));
  1097. WindowsAPI.SetPixel(hDC, rc.Right-3, rc.Top+1, 
  1098. ColorUtil.RGB(lightColor.R, 
  1099. lightColor.G, lightColor.B));
  1100. WindowsAPI.SetPixel(hDC, rc.Left+2, rc.Top+1, 
  1101. ColorUtil.RGB(lighterColor.R, 
  1102. lighterColor.G, lighterColor.B));
  1103. WindowsAPI.SetPixel(hDC, rc.Right-4, rc.Top+1, 
  1104. ColorUtil.RGB(lighterColor.R, 
  1105. lighterColor.G, lighterColor.B));
  1106. WindowsAPI.SetPixel(hDC, rc.Right-1, rc.Top+1, 
  1107. ColorUtil.RGB(darkColor.R, 
  1108. darkColor.G, darkColor.B));
  1109. g.ReleaseHdc(hDC);
  1110. g.DrawLine(colorPen, rc.Left, top, rc.Right-1, top);
  1111. g.DrawLine(colorPen, rc.Left+1, top+2, rc.Left+1, rc.Bottom-2);
  1112. g.DrawLine(colorPen, rc.Right-3, top+2, rc.Right-3, rc.Bottom-3);
  1113. g.DrawLine(lightPen, rc.Left+2, top+2, rc.Left+2, rc.Bottom-3);
  1114. g.DrawLine(lightPen, rc.Right-4, top+2, rc.Right-4, rc.Bottom-3);
  1115. g.DrawLine(lighterPen, rc.Left+3, top+2, rc.Left+3, rc.Bottom-3);
  1116. g.DrawLine(lighterPen, rc.Right-5, top+2, rc.Right-5, rc.Bottom-3);
  1117. g.DrawLine(darkPen, rc.Left, top+2, rc.Left, rc.Bottom-1);
  1118. g.DrawLine(darkPen, rc.Left+2, rc.Bottom-2, rc.Right-3, rc.Bottom-2);
  1119. g.DrawLine(darkPen, rc.Right-2, top+2, rc.Right-2, rc.Bottom-2);
  1120. g.DrawLine(darkerPen, rc.Left+1, rc.Bottom-1, rc.Right-1, rc.Bottom-1);
  1121. g.DrawLine(darkerPen, rc.Right-1, top+2, rc.Right-1, rc.Bottom-1);
  1122. }
  1123. // Cleanup
  1124. colorPen.Dispose();
  1125. lightPen.Dispose();
  1126. lighterPen.Dispose();
  1127. darkPen.Dispose();
  1128. darkerPen.Dispose();
  1129. }
  1130. void DrawWaitingGradientTubeForeground(Graphics g, Rectangle workRect)
  1131. {
  1132. Rectangle rc = workRect;
  1133. Pen colorPen = new Pen(gradientStartColor);
  1134. Pen lightPen = new Pen(lightColor);
  1135. Pen lighterPen = new Pen(lighterColor);
  1136. Pen darkPen = new Pen(darkColor);
  1137. Pen darkerPen = new Pen(darkerColor);
  1138. Region oldRegion = g.Clip;
  1139. g.Clip = new Region(rc);
  1140. if ( orientation == Orientation.Horizontal )
  1141. {
  1142. // Prepare helper settings
  1143. int numOfBands = (rc.Width/TUBE_WIDTH) + 2;
  1144. int adjust = rc.Left - TUBE_WIDTH + tubeOffset;
  1145. int height = rc.Height;
  1146. int bottom = rc.Bottom - 1;
  1147. int xPos = 0;
  1148. for ( int i = 0; i < numOfBands; i++ )
  1149. {
  1150. xPos = adjust + (i*TUBE_WIDTH);
  1151.             
  1152. // Draw regular color lines
  1153. g.DrawLine(darkerPen, xPos+1, rc.Top, xPos + height, bottom);
  1154. g.DrawLine(darkPen, xPos+2, rc.Top, xPos + height + 1, bottom);
  1155. g.DrawLine(darkPen, xPos+10, rc.Top, xPos + height + 9, bottom);
  1156. g.DrawLine(colorPen, xPos+3, rc.Top, xPos + height + 2, bottom);
  1157. g.DrawLine(colorPen, xPos+9, rc.Top, xPos + height + 8, bottom);
  1158. g.DrawLine(lightPen, xPos+4, rc.Top, xPos + height + 3, bottom);
  1159. g.DrawLine(lightPen, xPos+8, rc.Top, xPos + height + 7, bottom);
  1160. g.DrawLine(lighterPen, xPos+5, rc.Top, xPos + height + 4, bottom);
  1161. g.DrawLine(lighterPen, xPos+7, rc.Top, xPos + height + 6, bottom);
  1162. }
  1163. }
  1164. else
  1165. {
  1166. // Prepare helper settings
  1167. int numOfBands = (rc.Height/TUBE_WIDTH) + 2;
  1168. int adjust = rc.Bottom - TUBE_WIDTH + tubeOffset;
  1169. int height = rc.Width + 1;
  1170. int xPos1 = rc.Left;
  1171. int xPos2 = rc.Right + 1;
  1172. int yPos = rc.Top + 1;
  1173. for ( int i = 0; i < numOfBands; i++ )
  1174. {
  1175. yPos = adjust - (i*TUBE_WIDTH);
  1176.             
  1177. // Draw regular color lines
  1178. g.DrawLine(darkerPen, xPos1, yPos, xPos2, yPos + height);
  1179. g.DrawLine(darkPen, xPos1, yPos+1, xPos2, yPos + height+1);
  1180. g.DrawLine(darkPen, xPos1, yPos+9, xPos2, yPos+height+9);
  1181. g.DrawLine(colorPen, xPos1, yPos+2, xPos2, yPos+height+2);
  1182. g.DrawLine(colorPen, xPos1, yPos+8, xPos2, yPos+height+8);
  1183. g.DrawLine(lightPen, xPos1, yPos+3, xPos2, yPos+height+3);
  1184. g.DrawLine(lightPen, xPos1, yPos+7, xPos2, yPos+height+7);
  1185. g.DrawLine(lighterPen, xPos1, yPos+4, xPos2, yPos+height+4);
  1186. g.DrawLine(lighterPen, xPos1, yPos+6, xPos2, yPos+height+6);
  1187. }
  1188. }
  1189. // Cleanup
  1190. colorPen.Dispose();
  1191. lightPen.Dispose();
  1192. lighterPen.Dispose();
  1193. darkPen.Dispose();
  1194. darkerPen.Dispose();
  1195. g.Clip = oldRegion;
  1196. }
  1197. void DrawTwoColorsGradient(Graphics g, Rectangle workRect)
  1198. {
  1199. // Calculate color distance
  1200. int redStep = Math.Max(gradientEndColor.R, gradientStartColor.R) 
  1201. - Math.Min(gradientEndColor.R, gradientStartColor.R);
  1202. int greenStep = Math.Max(gradientEndColor.G, gradientStartColor.G) 
  1203. - Math.Min(gradientEndColor.G, gradientStartColor.G);
  1204. int blueStep = Math.Max(gradientEndColor.B, gradientStartColor.B) 
  1205. - Math.Min(gradientEndColor.B, gradientStartColor.B);
  1206. // Do we need to increase or decrease
  1207. int redDirection; 
  1208. if ( gradientEndColor.R > gradientStartColor.R ) 
  1209. redDirection = 1;
  1210. else
  1211. redDirection = -1;
  1212. int greenDirection;
  1213. if (  gradientEndColor.G >  gradientStartColor.G )
  1214. greenDirection = 1;
  1215. else
  1216. greenDirection = -1;
  1217. int blueDirection;
  1218. if ( gradientEndColor.B > gradientStartColor.B )
  1219. blueDirection = 1;
  1220. else
  1221. blueDirection = -1;
  1222. // how many segements we need to draw
  1223. int topGap = 1;
  1224. int leftGap = 2;
  1225. if ( smooth ) 
  1226. {
  1227. leftGap = 0;
  1228. topGap = 0;
  1229. }
  1230. if ( orientation == Orientation.Horizontal )
  1231. {
  1232. // The progress control won't allow its height to be anything other than
  1233. // and even number since the width of the segment needs to be a perfect 3/4
  1234. // of the control (height - 4) -- Four pixels are padding --
  1235. int segmentWidth = (workRect.Height)*3/4;
  1236. segmentWidth -= 2;
  1237. int numOfSegments = (workRect.Width)/(segmentWidth + leftGap);
  1238. // No point to continue if we don't have enough are for even one segment
  1239. if ( numOfSegments == 0 )
  1240. return;
  1241. // calculate the actual RGB steps for every segment
  1242. redStep /= numOfSegments;
  1243. greenStep /= numOfSegments;
  1244. blueStep /= numOfSegments;
  1245. Rectangle segmentRect = new Rectangle(workRect.Left, 
  1246. workRect.Top, segmentWidth, workRect.Height);
  1247.    
  1248. int progressWidth = (GetScaledValue());
  1249. if ( progressWidth < 0 ) progressWidth = 0;
  1250. int counter = 0;
  1251. for ( int i = 0; i < progressWidth; i += segmentRect.Width+leftGap )
  1252. {
  1253. // Check we stay within bounds
  1254. int red = gradientStartColor.R+(redStep*counter*redDirection);
  1255. int green = gradientStartColor.G+(greenStep*counter*greenDirection);
  1256. int blue = gradientStartColor.B+(blueStep*counter*blueDirection);
  1257. // Make gettting the current color safe
  1258. CheckBounds(ref red, ref green, ref blue);
  1259. Color currentColor = Color.FromArgb(red, green, blue);
  1260. if ( i+segmentRect.Width+leftGap > progressWidth 
  1261. && (i+segmentRect.Width+leftGap > workRect.Width-leftGap) ) 
  1262. {
  1263. // if we are about to leave because next segment does not fit
  1264. // draw the portion that fits
  1265. int partialWidth = progressWidth-i;
  1266. Rectangle drawingRect = new Rectangle(segmentRect.Left+i, 
  1267. segmentRect.Top+topGap, partialWidth, segmentRect.Height-(topGap*2));
  1268. g.FillRectangle(new SolidBrush(currentColor), drawingRect);
  1269. break;
  1270. }
  1271. Rectangle completeSegment = new Rectangle(segmentRect.Left+i, 
  1272. segmentRect.Top+topGap, segmentRect.Width, segmentRect.Height-(topGap*2));
  1273. g.FillRectangle(new SolidBrush(currentColor), completeSegment);
  1274. counter++;
  1275. }
  1276. }
  1277. else
  1278. {
  1279. topGap = 2;
  1280. leftGap = 1;
  1281. if ( smooth ) 
  1282. {
  1283. leftGap = 0;
  1284. topGap = 0;
  1285. }
  1286. // The progress control won't allow its height to be anything other than
  1287. // and even number 
  1288. int segmentHeight = (workRect.Width)*3/4;
  1289. segmentHeight -= 2;
  1290. int numOfSegments = (workRect.Height)/(segmentHeight + topGap);
  1291. // No point to continue if we don't have enough are for even one segment
  1292. if ( numOfSegments == 0 )
  1293. return;
  1294. // calculate the actual RGB steps for every segment
  1295. redStep /= numOfSegments;
  1296. greenStep /= numOfSegments;
  1297. blueStep /= numOfSegments;
  1298. Rectangle segmentRect = new Rectangle(workRect.Left, 
  1299. workRect.Top, workRect.Width, segmentHeight);
  1300.    
  1301. int progressHeight = GetScaledValue();
  1302. if ( progressHeight < 0 ) progressHeight = 0;
  1303. int counter = 0;
  1304. for ( int i = 0; i < progressHeight; i += segmentRect.Height+topGap )
  1305. {
  1306. // Check we stay within bounds
  1307. int red = gradientStartColor.R+(redStep*counter*redDirection);
  1308. int green = gradientStartColor.G+(greenStep*counter*greenDirection);
  1309. int blue = gradientStartColor.B+(blueStep*counter*blueDirection);
  1310. // Make gettting the current color safe
  1311. CheckBounds(ref red, ref green, ref blue);
  1312. Color currentColor = Color.FromArgb(red, green, blue);
  1313. int top = (workRect.Bottom - segmentRect.Height) - i;
  1314. if ( top < workRect.Top ) 
  1315. {
  1316. // if we are about to leave because next segment does not fit
  1317. // draw the portion that fits
  1318. int partialHeight = progressHeight-i;
  1319. Rectangle drawingRect = new Rectangle(segmentRect.Left+leftGap, 
  1320. workRect.Top, segmentRect.Width-(leftGap*2), partialHeight);
  1321. g.FillRectangle(new SolidBrush(currentColor), drawingRect);
  1322. break;
  1323. }
  1324. Rectangle completeSegment = new Rectangle(segmentRect.Left+leftGap, top, 
  1325. segmentRect.Width-(leftGap*2), segmentRect.Height);
  1326. g.FillRectangle(new SolidBrush(currentColor), completeSegment);
  1327. counter++;
  1328. }
  1329. }
  1330. }
  1331. void DrawThreeColorsGradient(Graphics g, Rectangle workRect)
  1332. {
  1333. // Calculate color distance for the first half
  1334. int redStepFirst = Math.Max(gradientStartColor.R, gradientMiddleColor.R) 
  1335. - Math.Min(gradientStartColor.R, gradientMiddleColor.R);
  1336. int greenStepFirst = Math.Max(gradientStartColor.G, gradientMiddleColor.G) 
  1337. - Math.Min(gradientStartColor.G, gradientMiddleColor.G);
  1338. int blueStepFirst = Math.Max(gradientStartColor.B, gradientMiddleColor.B) 
  1339. - Math.Min(gradientStartColor.B, gradientMiddleColor.B);
  1340.    
  1341. // Calculate color distance for the second half
  1342. int redStepSecond = Math.Max(gradientEndColor.R, gradientMiddleColor.R) 
  1343. - Math.Min(gradientEndColor.R, gradientMiddleColor.R);
  1344. int greenStepSecond = Math.Max(gradientEndColor.G, gradientMiddleColor.G) 
  1345. - Math.Min(gradientEndColor.G, gradientMiddleColor.G);
  1346. int blueStepSecond = Math.Max(gradientEndColor.B, gradientMiddleColor.B) 
  1347. - Math.Min(gradientEndColor.B, gradientMiddleColor.B);
  1348. // Do we need to increase or decrease for the first half
  1349. int redDirectionFirst; 
  1350. if ( gradientStartColor.R < gradientMiddleColor.R ) 
  1351. redDirectionFirst = 1;
  1352. else
  1353. redDirectionFirst = -1;
  1354. int greenDirectionFirst;
  1355. if (  gradientStartColor.G <  gradientMiddleColor.G )
  1356. greenDirectionFirst = 1;
  1357. else
  1358. greenDirectionFirst = -1;
  1359. int blueDirectionFirst;
  1360. if ( gradientStartColor.B < gradientMiddleColor.B )
  1361. blueDirectionFirst = 1;
  1362. else
  1363. blueDirectionFirst = -1;
  1364. // Do we need to increase or decrease for the second half
  1365. int redDirectionSecond; 
  1366. if ( gradientMiddleColor.R < gradientEndColor.R ) 
  1367. redDirectionSecond = 1;
  1368. else
  1369. redDirectionSecond = -1;
  1370. int greenDirectionSecond;
  1371. if (  gradientMiddleColor.G <  gradientEndColor.G )
  1372. greenDirectionSecond = 1;
  1373. else
  1374. greenDirectionSecond = -1;
  1375. int blueDirectionSecond;
  1376. if ( gradientMiddleColor.B < gradientEndColor.B )
  1377. blueDirectionSecond = 1;
  1378. else
  1379. blueDirectionSecond = -1;
  1380. // how many segements we need to draw
  1381. int topGap = 1;
  1382. int leftGap = 2;
  1383. if ( smooth ) 
  1384. {
  1385. topGap = 0;
  1386. leftGap = 0;
  1387. }
  1388. if ( orientation == Orientation.Horizontal )
  1389. {
  1390. // The progress control won't allow its height to be anything other than
  1391. // and even number since the width of the segment needs to be a perfect 3/4
  1392. // of the control (height - 4) -- Four pixels are padding --
  1393. int segmentWidth = (workRect.Height)*3/4;
  1394. segmentWidth -= 2;
  1395. int numOfSegments = (workRect.Width)/(segmentWidth + leftGap);
  1396. // calculate the actual RGB step for every segment
  1397. int segments = (numOfSegments/2);
  1398. // Be safe
  1399. if ( segments == 0 )
  1400. segments = 1;
  1401. redStepFirst /= segments;
  1402. greenStepFirst /= segments;;
  1403. blueStepFirst /= segments;
  1404. redStepSecond /= segments;
  1405. greenStepSecond /= segments;
  1406. blueStepSecond /= segments;;
  1407. Rectangle segmentRect = new Rectangle(workRect.Left, 
  1408. workRect.Top, segmentWidth, workRect.Height);
  1409.    
  1410. int progressWidth = GetScaledValue();
  1411. if ( progressWidth < 0 ) progressWidth = 0;
  1412. int counter = 0;
  1413. bool counterReset = true;
  1414. int red;
  1415. int green;
  1416. int blue;
  1417. for ( int i = 0; i < progressWidth; i += segmentRect.Width+leftGap )
  1418. {
  1419. Color currentColor = Color.Empty;
  1420. if ( i < (workRect.Width)/2 )
  1421. {
  1422. red  = gradientStartColor.R+(redStepFirst*counter*redDirectionFirst);
  1423. green = gradientStartColor.G+(greenStepFirst*counter*greenDirectionFirst);
  1424. blue = gradientStartColor.B+(blueStepFirst*counter*blueDirectionFirst);
  1425. // Check we stay within bounds
  1426. CheckBounds(ref red, ref green, ref blue);
  1427. currentColor = Color.FromArgb(red, green, blue);
  1428. }
  1429. else
  1430. {
  1431. if ( counterReset )
  1432. {
  1433. counterReset = false;
  1434. counter = 0;
  1435. }
  1436. red = gradientMiddleColor.R+(redStepSecond*counter*redDirectionSecond);
  1437. green = gradientMiddleColor.G+(greenStepSecond*counter*greenDirectionSecond);
  1438. blue = gradientMiddleColor.B+(blueStepSecond*counter*blueDirectionSecond);
  1439. // Check we stay within bounds
  1440. CheckBounds(ref red, ref green, ref blue);
  1441. currentColor = Color.FromArgb(red,green, blue); 
  1442. }
  1443. if ( i+segmentRect.Width+leftGap > progressWidth 
  1444. && (i+segmentRect.Width+leftGap > workRect.Width-leftGap) ) 
  1445. {
  1446. // if we are about to leave because next segment does not fit
  1447. // draw the portion that fits
  1448. int partialWidth = progressWidth-i;
  1449. Rectangle drawingRect = new Rectangle(segmentRect.Left+i, 
  1450. segmentRect.Top+topGap, partialWidth, segmentRect.Height-(topGap*2));
  1451. g.FillRectangle(new SolidBrush(currentColor), drawingRect);
  1452. break;
  1453. }
  1454. Rectangle completeSegment = new Rectangle(segmentRect.Left+i, 
  1455. segmentRect.Top+topGap, segmentRect.Width, segmentRect.Height-(topGap*2));
  1456. g.FillRectangle(new SolidBrush(currentColor), completeSegment);
  1457. counter++;
  1458. }
  1459. }
  1460. else
  1461. {
  1462. topGap = 2;
  1463. leftGap = 1;
  1464. if ( smooth ) 
  1465. {
  1466. topGap = 0;
  1467. leftGap = 0;
  1468. }
  1469. // The progress control won't allow its height to be anything other than
  1470. // and even number since the width of the segment needs to be a perfect 3/4
  1471. // of the control (height - 4) -- Four pixels are padding --
  1472. int segmentHeight = (workRect.Width)*3/4;
  1473. segmentHeight -= 2;
  1474. int numOfSegments = (workRect.Height)/(segmentHeight + topGap);
  1475. // calculate the actual RGB step for every segment
  1476. int segments = (numOfSegments/2);
  1477. // Be safe
  1478. if ( segments == 0 )
  1479. segments = 1;
  1480. redStepFirst /= segments;
  1481. greenStepFirst /= segments;;
  1482. blueStepFirst /= segments;
  1483. redStepSecond /= segments;
  1484. greenStepSecond /= segments;
  1485. blueStepSecond /= segments;;
  1486. Rectangle segmentRect = new Rectangle(workRect.Left, 
  1487. workRect.Top, workRect.Width, segmentHeight);
  1488.    
  1489. int progressHeight = GetScaledValue();
  1490. if ( progressHeight < 0 ) progressHeight = 0;
  1491. int counter = 0;
  1492. bool counterReset = true;
  1493. int red;
  1494. int green;
  1495. int blue;
  1496. for ( int i = 0; i < progressHeight; i += segmentRect.Height+topGap )
  1497. {
  1498. Color currentColor = Color.Empty;
  1499. if ( i < (workRect.Height)/2 )
  1500. {
  1501. red  = gradientStartColor.R+(redStepFirst*counter*redDirectionFirst);
  1502. green = gradientStartColor.G+(greenStepFirst*counter*greenDirectionFirst);
  1503. blue = gradientStartColor.B+(blueStepFirst*counter*blueDirectionFirst);
  1504. // Check we stay within bounds
  1505. CheckBounds(ref red, ref green, ref blue);
  1506. currentColor = Color.FromArgb(red, green, blue);
  1507. }
  1508. else
  1509. {
  1510. if ( counterReset )
  1511. {
  1512. counterReset = false;
  1513. counter = 0;
  1514. }
  1515. red = gradientMiddleColor.R+(redStepSecond*counter*redDirectionSecond);
  1516. green = gradientMiddleColor.G+(greenStepSecond*counter*greenDirectionSecond);
  1517. blue = gradientMiddleColor.B+(blueStepSecond*counter*blueDirectionSecond);
  1518. // Check we stay within bounds
  1519. CheckBounds(ref red, ref green, ref blue);
  1520. currentColor = Color.FromArgb(red,green, blue); 
  1521. }
  1522. int top = (workRect.Bottom - segmentRect.Height) - i;
  1523. if ( top < workRect.Top ) 
  1524. {
  1525. // if we are about to leave because next segment does not fit
  1526. // draw the portion that fits
  1527. int partialHeight = progressHeight-i;
  1528. Rectangle drawingRect = new Rectangle(segmentRect.Left+leftGap, 
  1529. workRect.Top, segmentRect.Width-(leftGap*2), partialHeight);
  1530. g.FillRectangle(new SolidBrush(currentColor), drawingRect);
  1531. break;
  1532. }
  1533. Rectangle completeSegment = new Rectangle(segmentRect.Left+leftGap, top, 
  1534. segmentRect.Width-(leftGap*2), segmentRect.Height);
  1535. g.FillRectangle(new SolidBrush(currentColor), completeSegment);
  1536. counter++;
  1537. }
  1538. }
  1539. }
  1540. void CheckBounds(ref int red, ref int green, ref int blue)
  1541. {
  1542. // Make sure we stay in bounds
  1543. if ( red < 0 ) red = 0;
  1544. else if ( red > 255 ) red = 255;
  1545. if ( green < 0 ) green = 0;
  1546. else if ( green > 255 ) green = 255;
  1547. if ( blue < 0 ) blue = 0;
  1548. else if ( blue > 255 ) blue = 255;
  1549. }
  1550. void DrawStandardForegroundSegmented(Graphics g, Rectangle workRect)
  1551. {
  1552. if ( orientation == Orientation.Horizontal )
  1553. {
  1554. // The progress control won't allow its height to be anything other than
  1555. // and even number since the width of the segment needs to be a perfect 3/4
  1556. // of the control (height - 4) -- Four pixels are padding for the border--
  1557. int segmentWidth = (workRect.Height)*3/4;
  1558. int segmentTopGap = 1;
  1559. int segmentLeftGap = 2;
  1560. // One pixel gap of the sides
  1561. segmentWidth -= 2;
  1562.                         
  1563. Rectangle segmentRect = new Rectangle(workRect.Left, 
  1564. workRect.Top, segmentWidth, workRect.Height);
  1565. int progressWidth = GetScaledValue();
  1566. if ( progressWidth < 0 ) progressWidth = 0;
  1567. for ( int i = 0; i < progressWidth; i += segmentRect.Width+segmentLeftGap )
  1568. {
  1569. if ( i+segmentRect.Width+segmentLeftGap > progressWidth && (i+segmentRect.Width+workRect.Left > workRect.Width) ) 
  1570. {
  1571. // if we are about to leave because next segment does not fit
  1572. // draw the portion that fits
  1573. int partialWidth = progressWidth-i;
  1574. g.FillRectangle(new SolidBrush(foregroundColor), 
  1575. segmentRect.Left+i, segmentRect.Top+segmentTopGap, partialWidth, segmentRect.Height-(segmentTopGap*2));
  1576. break;
  1577. }
  1578. g.FillRectangle(new SolidBrush(foregroundColor), segmentRect.Left+i, segmentRect.Top+segmentTopGap, 
  1579. segmentRect.Width, segmentRect.Height-(segmentTopGap*2));
  1580. }
  1581. }
  1582. else
  1583. {
  1584. int segmentHeight = (workRect.Width)*3/4;
  1585. int segmentTopGap = 2;
  1586. int segmentLeftGap = 1;
  1587. // One pixel gap on the top and bottom
  1588. segmentHeight -= 2;
  1589.                         
  1590. Rectangle segmentRect = new Rectangle(workRect.Left, 
  1591. workRect.Top, workRect.Width, segmentHeight);
  1592. int progressHeight = GetScaledValue();
  1593. if ( progressHeight < 0 ) progressHeight = 0;
  1594. for ( int i = 0; i < progressHeight; i += segmentRect.Height+segmentTopGap )
  1595. {
  1596. int top = (workRect.Bottom - segmentRect.Height) - i;
  1597. if ( top < workRect.Top ) 
  1598. {
  1599. // if we are about to leave because next segment does not fit
  1600. // draw the portion that fits
  1601. int partialHeight = progressHeight-i;
  1602. g.FillRectangle(new SolidBrush(foregroundColor), 
  1603. segmentRect.Left+segmentLeftGap, WorkRect.Top, 
  1604. segmentRect.Width-(segmentLeftGap*2), partialHeight);
  1605. break;
  1606. }
  1607. Rectangle fillRect =  new Rectangle(segmentRect.Left+segmentLeftGap, top, 
  1608. segmentRect.Width-(segmentLeftGap*2), segmentRect.Height);
  1609. g.FillRectangle(new SolidBrush(foregroundColor), fillRect);
  1610. }
  1611. }
  1612. }
  1613. void DrawStandardForegroundSmooth(Graphics g, Rectangle workRect)
  1614. {
  1615. int progressValue = GetScaledValue();
  1616.             bool horizontalOrientation = (orientation == Orientation.Horizontal);
  1617. int top = 0;
  1618. if ( horizontalOrientation )
  1619. {
  1620. g.FillRectangle(new SolidBrush(foregroundColor), workRect.Left, workRect.Top, 
  1621. progressValue, workRect.Height);
  1622. }
  1623. else
  1624. {
  1625. top = workRect.Top + (workRect.Height - progressValue);
  1626. g.FillRectangle(new SolidBrush(foregroundColor), workRect.Left, top,
  1627. workRect.Width, progressValue);
  1628. }
  1629. if ( ShowProgressText)
  1630. {
  1631. int percent = 0;
  1632. if ( horizontalOrientation )
  1633.                     percent = GetScaledValue()*100/workRect.Width;
  1634. else
  1635. percent = GetScaledValue()*100/workRect.Height;
  1636. string text;
  1637. if ( progressText == string.Empty )
  1638.                     text = percent.ToString() + " " + "%";
  1639. else
  1640. text = progressText;
  1641. Size size = TextUtil.GetTextSize(g, text, Font);
  1642. // Draw first part of the text in hightlight color in case it needs to be
  1643. Rectangle clipRect = Rectangle.Empty;
  1644. Point pos = Point.Empty;
  1645. int topGap = 0;
  1646. if ( enable3DBorder == true )
  1647. topGap = 1;
  1648. if ( horizontalOrientation )
  1649. {
  1650. clipRect = new Rectangle(workRect.Left, workRect.Top,
  1651. progressValue, workRect.Height);
  1652. pos = new Point((workRect.Width - size.Width)/2, 
  1653. (workRect.Height - size.Height)/2 + topGap);
  1654. }
  1655. else
  1656. {
  1657. clipRect = new Rectangle(workRect.Left, top,
  1658. workRect.Width, progressValue);
  1659. pos = new Point((workRect.Width - size.Height)/2,
  1660. (workRect.Height - size.Width)/2); 
  1661. }
  1662. g.Clip = new Region(clipRect);
  1663. Color textColor = progressTextHiglightColor;
  1664. if ( textColor == Color.Empty )
  1665. textColor = SystemColors.HighlightText;
  1666. if ( horizontalOrientation )
  1667. {
  1668. g.DrawString(text, Font, new SolidBrush(textColor), pos);
  1669. }
  1670. else
  1671. {
  1672. StringFormat format = new StringFormat();
  1673. format.FormatFlags = StringFormatFlags.DirectionVertical;
  1674. g.DrawString(text, Font, new SolidBrush(textColor), pos, format);
  1675. }
  1676. // Draw rest in control text color if it needs to be
  1677. if ( horizontalOrientation )
  1678. {
  1679. clipRect = new Rectangle(progressValue+workRect.Left, workRect.Top,
  1680. workRect.Width, workRect.Height);
  1681. }
  1682. else
  1683. {
  1684. clipRect = new Rectangle(workRect.Left, workRect.Top, 
  1685. workRect.Width,  workRect.Height - progressValue);
  1686. }
  1687. g.Clip = new Region(clipRect);
  1688. textColor = progressTextColor;
  1689. if ( textColor == Color.Empty )
  1690. textColor = SystemColors.ControlText;
  1691. if ( horizontalOrientation )
  1692. {
  1693. g.DrawString(text, Font, new SolidBrush(textColor), pos);
  1694. }
  1695. else
  1696. {
  1697. StringFormat format = new StringFormat();
  1698. format.FormatFlags = StringFormatFlags.DirectionVertical;
  1699. g.DrawString(text, Font, new SolidBrush(textColor), pos, format);
  1700. }
  1701. }
  1702. }
  1703. void OnWaitingTick(object sender, EventArgs e)
  1704. {
  1705. // Increase position
  1706. if ( barType == ProgressBarType.WaitingGradient )
  1707. {
  1708. if ( orientation == Orientation.Horizontal )
  1709. waitingPos += waitingStep;
  1710. else
  1711. waitingPos -= waitingStep;
  1712. // Reset
  1713. Rectangle rc = WorkRect;
  1714. if ( orientation == Orientation.Horizontal && waitingPos > rc.Width )
  1715. {
  1716. waitingPos = rc.Left;
  1717. }
  1718. else if ( orientation == Orientation.Vertical && waitingPos < rc.Top )
  1719. {
  1720. waitingPos = rc.Bottom;
  1721. }
  1722. }
  1723. else if (  barType == ProgressBarType.WaitingGradientTube )
  1724. {
  1725. if ( orientation == Orientation.Horizontal )
  1726. {
  1727. if ( ++tubeOffset > TUBE_WIDTH-1)
  1728. tubeOffset = 0;
  1729. }
  1730. else
  1731. {
  1732. if (--tubeOffset < 0 )
  1733.                         tubeOffset = TUBE_WIDTH;
  1734. }
  1735. }
  1736. // Repaint control
  1737. Invalidate();
  1738. }
  1739. int GetScaledValue()
  1740. {
  1741. int scaledValue = _value;
  1742. Rectangle rc = ClientRectangle;
  1743. if ( enable3DBorder )
  1744. rc.Inflate(-2, -2);
  1745. else
  1746. rc.Inflate(-1,-1);
  1747. if ( orientation == Orientation.Horizontal )
  1748.                 scaledValue = (_value-min)*rc.Width/(max - min);
  1749. else
  1750. scaledValue = (_value-min)*rc.Height/(max - min);
  1751. return scaledValue;
  1752. }
  1753. void InitializeGradientTubeColors(Color color)
  1754. {
  1755. // The ControlPaint class does not gives me the distribuition of color
  1756. // that I am looking for
  1757. lightColor = ColorUtil.LightColor(color, 51);
  1758. lighterColor = ColorUtil.LightColor(lightColor, 51);
  1759. lightestColor = ColorUtil.LightColor(lighterColor, 51);
  1760. darkColor = ColorUtil.DarkColor(color, 51);
  1761. darkerColor = ColorUtil.DarkColor(darkColor, 51);
  1762. }
  1763. // Properties
  1764. internal Rectangle WorkRect
  1765. {
  1766. get 
  1767. {
  1768. Rectangle rc = ClientRectangle;
  1769. if ( enable3DBorder )
  1770. rc.Inflate(-2, -2);
  1771. else
  1772. rc.Inflate(-1, -1);
  1773. return rc;
  1774. }
  1775. }
  1776. #endregion
  1777. }
  1778. }