UCProcessExt.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. // ***********************************************************************
  2. // Assembly : HZH_Controls
  3. // Created : 08-08-2019
  4. //
  5. // ***********************************************************************
  6. // <copyright file="UCProcessExt.cs">
  7. // Copyright by Huang Zhenghui(黄正辉) All, QQ group:568015492 QQ:623128629 Email:623128629@qq.com
  8. // </copyright>
  9. //
  10. // Blog: https://www.cnblogs.com/bfyx
  11. // GitHub:https://github.com/kwwwvagaa/NetWinformControl
  12. // gitee:https://gitee.com/kwwwvagaa/net_winform_custom_control.git
  13. //
  14. // If you use this code, please keep this note.
  15. // ***********************************************************************
  16. using System;
  17. using System.Collections.Generic;
  18. using System.ComponentModel;
  19. using System.Drawing;
  20. using System.Data;
  21. using System.Linq;
  22. using System.Text;
  23. using System.Windows.Forms;
  24. namespace HZH_Controls.Controls
  25. {
  26. /// <summary>
  27. /// Class UCProcessExt.
  28. /// Implements the <see cref="HZH_Controls.Controls.UCControlBase" />
  29. /// </summary>
  30. /// <seealso cref="HZH_Controls.Controls.UCControlBase" />
  31. public partial class UCProcessExt : UCControlBase
  32. {
  33. /// <summary>
  34. /// The value
  35. /// </summary>
  36. private int _value = 0;
  37. /// <summary>
  38. /// Gets or sets the value.
  39. /// </summary>
  40. /// <value>The value.</value>
  41. public int Value
  42. {
  43. get { return this._value; }
  44. set
  45. {
  46. if (value < 0)
  47. return;
  48. this._value = value;
  49. SetValue();
  50. }
  51. }
  52. /// <summary>
  53. /// The maximum value
  54. /// </summary>
  55. private int maxValue = 100;
  56. /// <summary>
  57. /// Gets or sets the maximum value.
  58. /// </summary>
  59. /// <value>The maximum value.</value>
  60. public int MaxValue
  61. {
  62. get { return maxValue; }
  63. set
  64. {
  65. if (value <= 0)
  66. return;
  67. maxValue = value;
  68. SetValue();
  69. }
  70. }
  71. /// <summary>
  72. /// Sets the value.
  73. /// </summary>
  74. private void SetValue()
  75. {
  76. double dbl = (double)_value / (double)maxValue;
  77. this.panel1.Width = (int)(this.Width * dbl);
  78. }
  79. /// <summary>
  80. /// Initializes a new instance of the <see cref="UCProcessExt" /> class.
  81. /// </summary>
  82. public UCProcessExt()
  83. {
  84. InitializeComponent();
  85. }
  86. /// <summary>
  87. /// Handles the SizeChanged event of the ProcessExt control.
  88. /// </summary>
  89. /// <param name="sender">The source of the event.</param>
  90. /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
  91. private void ProcessExt_SizeChanged(object sender, EventArgs e)
  92. {
  93. SetValue();
  94. }
  95. /// <summary>
  96. /// Steps this instance.
  97. /// </summary>
  98. public void Step()
  99. {
  100. Value++;
  101. }
  102. }
  103. }