DecimalScopeControl.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. using System;
  2. using System.Windows.Forms;
  3. namespace PaintDotNet.CustomControl
  4. {
  5. public partial class DecimalScopeControl : BaseUserControl
  6. {
  7. /// <summary>
  8. /// 参数的index
  9. /// </summary>
  10. public int paramIndex;
  11. /// <summary>
  12. /// 参数值改变
  13. /// </summary>
  14. public event EventHandler ValueChanged;
  15. /// <summary>
  16. /// 默认不显示进度条
  17. /// </summary>
  18. private bool showTrackBar = false;
  19. /// <summary>
  20. /// 十进制位数
  21. /// </summary>
  22. public int DecimalPlaces
  23. {
  24. get
  25. {
  26. return this.numericUpDown1.DecimalPlaces;
  27. }
  28. set
  29. {
  30. this.numericUpDown1.DecimalPlaces = value;
  31. this.numericUpDown1.Increment = (decimal)Math.Pow(0.1, DecimalPlaces);
  32. this.numericUpDown2.DecimalPlaces = value;
  33. this.numericUpDown2.Increment = (decimal)Math.Pow(0.1, DecimalPlaces);
  34. }
  35. }
  36. public double Maximum
  37. {
  38. get
  39. {
  40. return (double)numericUpDown1.Maximum;
  41. }
  42. set
  43. {
  44. this.numericUpDown1.Maximum = (Decimal)value;
  45. this.numericUpDown2.Maximum = (Decimal)value;
  46. }
  47. }
  48. /// <summary>
  49. /// 如果numericUpDown2的最大值发生变化
  50. /// 则初始化数据和拖动条数据
  51. /// </summary>
  52. public decimal Maximum2
  53. {
  54. set
  55. {
  56. this.numericUpDown2.Maximum = value;
  57. this.minValue = 0.00;
  58. this.maxValue = 0.00;
  59. if (showTrackBar)
  60. {
  61. this.doubleSlidingTrackbar.maxValue = value;
  62. this.doubleSlidingTrackbar.InitLeftRightPoints();
  63. }
  64. }
  65. }
  66. public double Minimum
  67. {
  68. get
  69. {
  70. return (double)numericUpDown1.Minimum;
  71. }
  72. set
  73. {
  74. this.numericUpDown1.Minimum = (Decimal)value;
  75. this.numericUpDown2.Minimum = (Decimal)value;
  76. }
  77. }
  78. public double minValue
  79. {
  80. get
  81. {
  82. return (double)numericUpDown1.Value;
  83. }
  84. set
  85. {
  86. this.numericUpDown1.Value = (decimal)value;
  87. }
  88. }
  89. public double maxValue
  90. {
  91. get
  92. {
  93. return (double)numericUpDown2.Value;
  94. }
  95. set
  96. {
  97. this.numericUpDown2.Value = (decimal)value;
  98. }
  99. }
  100. /// <summary>
  101. /// 默认构造函数
  102. /// </summary>
  103. public DecimalScopeControl()
  104. {
  105. InitializeComponent();
  106. InitializeLanguageText();
  107. }
  108. /// <summary>
  109. /// 用于修改文字
  110. /// </summary>
  111. /// <param name="label"></param>
  112. public DecimalScopeControl(string label)
  113. {
  114. InitializeComponent();
  115. InitializeLanguageText();
  116. this.label1.Text = label;
  117. }
  118. public DecimalScopeControl(string label, bool showTB, int length)
  119. {
  120. InitializeComponent();
  121. InitializeLanguageText();
  122. this.label1.Text = label;
  123. this.showTrackBar = showTB;
  124. if (!this.showTrackBar)
  125. {
  126. this.numericUpDown1.Location = new System.Drawing.Point(0, 1);
  127. this.numericUpDown2.Location = new System.Drawing.Point(45, 1);
  128. }
  129. else
  130. {
  131. this.doubleSlidingTrackbar = new DoubleSlidingTrackbar(length);
  132. this.doubleSlidingTrackbar.Location = new System.Drawing.Point(this.numericUpDown1.Location.X + this.numericUpDown1.Width+5, 1);
  133. this.doubleSlidingTrackbar.LeftHandlerDrag += new EventHandler(this.LeftHandlerDrag);
  134. this.doubleSlidingTrackbar.RightHandlerDrag += new EventHandler(this.RightHandlerDrag);
  135. this.doubleSlidingTrackbar.maxValue = this.numericUpDown2.Maximum;
  136. this.Controls.Add(this.doubleSlidingTrackbar);
  137. this.numericUpDown2.Location = new System.Drawing.Point(this.numericUpDown1.Location.X + this.numericUpDown1.Width + 5 + length, 1);
  138. }
  139. }
  140. private void RightHandlerDrag(object sender, EventArgs e)
  141. {
  142. this.numericUpDown2.Value = (decimal)((DoubleSlidingTrackbar)sender).GetRightSliderValue();
  143. }
  144. private void LeftHandlerDrag(object sender, EventArgs e)
  145. {
  146. this.numericUpDown1.Value = (decimal)((DoubleSlidingTrackbar)sender).GetLeftSliderValue();
  147. }
  148. /// <summary>
  149. /// 用于隐藏文字Label,并修改numericUpDown位置
  150. /// </summary>
  151. /// <param name="noVisible"></param>
  152. public DecimalScopeControl(bool noVisible)
  153. {
  154. InitializeComponent();
  155. InitializeLanguageText();
  156. this.Controls.Remove(this.label1);
  157. }
  158. private void numericUpDown1_ValueChanged(object sender, EventArgs e)
  159. {
  160. numericUpDown2.Value = Math.Max(numericUpDown2.Value, (numericUpDown1.Value> numericUpDown2.Maximum ? numericUpDown2.Maximum : numericUpDown1.Value));
  161. if (this.ValueChanged != null)
  162. {
  163. this.ValueChanged(this.numericUpDown1, e);
  164. }
  165. if (showTrackBar)
  166. {
  167. this.doubleSlidingTrackbar.SetLeftSliderPos(minValue);
  168. }
  169. }
  170. private void numericUpDown2_ValueChanged(object sender, EventArgs e)
  171. {
  172. numericUpDown1.Value = Math.Min(numericUpDown2.Value, numericUpDown1.Value);
  173. if (this.ValueChanged != null)
  174. {
  175. this.ValueChanged(this.numericUpDown2, e);
  176. }
  177. if (showTrackBar)
  178. {
  179. this.doubleSlidingTrackbar.SetRightSliderPos(maxValue);
  180. }
  181. }
  182. #region 组件设计器生成的代码
  183. private void InitializeLanguageText()
  184. {
  185. if(!DesignMode)
  186. this.label1.Text = PdnResources.GetString("Menu.Colorinterval.text") + ":";
  187. }
  188. /// <summary>
  189. /// 设计器支持所需的方法 - 不要修改
  190. /// 使用代码编辑器修改此方法的内容。
  191. /// </summary>
  192. private void InitializeComponent()
  193. {
  194. this.numericUpDown2 = new System.Windows.Forms.NumericUpDown();
  195. this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
  196. this.label1 = new System.Windows.Forms.Label();
  197. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit();
  198. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
  199. this.SuspendLayout();
  200. //
  201. // numericUpDown1
  202. //
  203. this.numericUpDown1.Location = new System.Drawing.Point(65, 1);
  204. this.numericUpDown1.Maximum = new decimal(new int[] {
  205. int.MaxValue,
  206. 0,
  207. 0,
  208. 0});
  209. this.numericUpDown1.Name = "numericUpDown1";
  210. this.numericUpDown1.Tag = "min";
  211. this.numericUpDown1.Size = new System.Drawing.Size(40, 21);
  212. this.numericUpDown1.TabIndex = 12;
  213. this.numericUpDown1.ValueChanged += new System.EventHandler(this.numericUpDown1_ValueChanged);
  214. //
  215. // numericUpDown2
  216. //
  217. this.numericUpDown2.Location = new System.Drawing.Point(110, 1);
  218. this.numericUpDown2.Maximum = new decimal(new int[] {
  219. int.MaxValue,
  220. 0,
  221. 0,
  222. 0});
  223. this.numericUpDown2.Name = "numericUpDown2";
  224. this.numericUpDown2.Tag = "max";
  225. this.numericUpDown2.Size = new System.Drawing.Size(40, 21);
  226. this.numericUpDown2.TabIndex = 13;
  227. this.numericUpDown2.ValueChanged += new System.EventHandler(this.numericUpDown2_ValueChanged);
  228. //
  229. // label1
  230. //
  231. this.label1.AutoSize = true;
  232. this.label1.Location = new System.Drawing.Point(1, 4);
  233. this.label1.Name = "label1";
  234. this.label1.Size = new System.Drawing.Size(65, 12);
  235. this.label1.TabIndex = 14;
  236. this.label1.Text = "颜色区间:";
  237. //
  238. // DecimalScopeControl
  239. //
  240. this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
  241. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  242. this.Controls.Add(this.numericUpDown2);
  243. this.Controls.Add(this.numericUpDown1);
  244. this.Controls.Add(this.label1);
  245. this.Name = "DecimalScopeControl";
  246. this.Size = new System.Drawing.Size(150, 22);
  247. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit();
  248. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
  249. this.ResumeLayout(false);
  250. this.PerformLayout();
  251. }
  252. #endregion
  253. public DoubleSlidingTrackbar doubleSlidingTrackbar;
  254. public System.Windows.Forms.NumericUpDown numericUpDown2;
  255. public System.Windows.Forms.NumericUpDown numericUpDown1;
  256. private System.Windows.Forms.Label label1;
  257. }
  258. }