DecimalScopeControl.cs 9.5 KB

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