123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287 |
- using System;
- using System.Windows.Forms;
- namespace PaintDotNet.CustomControl
- {
- public partial class DecimalScopeControl : BaseUserControl
- {
- /// <summary>
- /// 参数的index
- /// </summary>
- public int paramIndex;
-
- /// <summary>
- /// 参数值改变
- /// </summary>
- public event EventHandler ValueChanged;
- /// <summary>
- /// 默认不显示进度条
- /// </summary>
- private bool showTrackBar = false;
- /// <summary>
- /// 十进制位数
- /// </summary>
- public int DecimalPlaces
- {
- get
- {
- return this.numericUpDown1.DecimalPlaces;
- }
- set
- {
- this.numericUpDown1.DecimalPlaces = value;
- this.numericUpDown1.Increment = (decimal)Math.Pow(0.1, DecimalPlaces);
- this.numericUpDown2.DecimalPlaces = value;
- this.numericUpDown2.Increment = (decimal)Math.Pow(0.1, DecimalPlaces);
- }
- }
- public double Maximum
- {
- get
- {
- return (double)numericUpDown1.Maximum;
- }
- set
- {
- this.numericUpDown1.Maximum = (Decimal)value;
- this.numericUpDown2.Maximum = (Decimal)value;
- }
- }
- /// <summary>
- /// 如果numericUpDown2的最大值发生变化
- /// 则初始化数据和拖动条数据
- /// </summary>
- public decimal Maximum2
- {
- set
- {
- this.numericUpDown2.Maximum = value;
- this.minValue = 0.00;
- this.maxValue = 0.00;
- if (showTrackBar)
- {
- this.doubleSlidingTrackbar.maxValue = value;
- this.doubleSlidingTrackbar.InitLeftRightPoints();
- }
- }
- }
- public double Minimum
- {
- get
- {
- return (double)numericUpDown1.Minimum;
- }
- set
- {
- this.numericUpDown1.Minimum = (Decimal)value;
- this.numericUpDown2.Minimum = (Decimal)value;
- }
- }
- public double minValue
- {
- get
- {
- return (double)numericUpDown1.Value;
- }
- set
- {
- this.numericUpDown1.Value = (decimal)value;
- }
- }
- public double maxValue
- {
- get
- {
- return (double)numericUpDown2.Value;
- }
- set
- {
- this.numericUpDown2.Value = (decimal)value;
- }
- }
- /// <summary>
- /// 默认构造函数
- /// </summary>
- public DecimalScopeControl()
- {
- InitializeComponent();
- InitializeLanguageText();
- }
- /// <summary>
- /// 用于修改文字
- /// </summary>
- /// <param name="label"></param>
- public DecimalScopeControl(string label)
- {
- InitializeComponent();
- InitializeLanguageText();
- this.label1.Text = label;
- }
- public DecimalScopeControl(string label, bool showTB, int length)
- {
- InitializeComponent();
- InitializeLanguageText();
- this.label1.Text = label;
- this.showTrackBar = showTB;
- if (!this.showTrackBar)
- {
- this.numericUpDown1.Location = new System.Drawing.Point(0, 1);
- this.numericUpDown2.Location = new System.Drawing.Point(45, 1);
- }
- else
- {
- this.doubleSlidingTrackbar = new DoubleSlidingTrackbar(length);
- this.doubleSlidingTrackbar.Location = new System.Drawing.Point(this.numericUpDown1.Location.X + this.numericUpDown1.Width+5, 1);
- this.doubleSlidingTrackbar.LeftHandlerDrag += new EventHandler(this.LeftHandlerDrag);
- this.doubleSlidingTrackbar.RightHandlerDrag += new EventHandler(this.RightHandlerDrag);
- this.doubleSlidingTrackbar.maxValue = this.numericUpDown2.Maximum;
- this.Controls.Add(this.doubleSlidingTrackbar);
- this.numericUpDown2.Location = new System.Drawing.Point(this.numericUpDown1.Location.X + this.numericUpDown1.Width + 5 + length, 1);
- }
- }
- private void RightHandlerDrag(object sender, EventArgs e)
- {
- this.numericUpDown2.Value = (decimal)((DoubleSlidingTrackbar)sender).GetRightSliderValue();
- }
- private void LeftHandlerDrag(object sender, EventArgs e)
- {
- this.numericUpDown1.Value = (decimal)((DoubleSlidingTrackbar)sender).GetLeftSliderValue();
- }
- /// <summary>
- /// 用于隐藏文字Label,并修改numericUpDown位置
- /// </summary>
- /// <param name="noVisible"></param>
- public DecimalScopeControl(bool noVisible)
- {
- InitializeComponent();
- InitializeLanguageText();
- this.Controls.Remove(this.label1);
- }
- private void numericUpDown1_ValueChanged(object sender, EventArgs e)
- {
- numericUpDown2.Value = Math.Max(numericUpDown2.Value, (numericUpDown1.Value> numericUpDown2.Maximum ? numericUpDown2.Maximum : numericUpDown1.Value));
- if (this.ValueChanged != null)
- {
- this.ValueChanged(this.numericUpDown1, e);
- }
- if (showTrackBar)
- {
- this.doubleSlidingTrackbar.SetLeftSliderPos(minValue);
- }
- }
- private void numericUpDown2_ValueChanged(object sender, EventArgs e)
- {
- numericUpDown1.Value = Math.Min(numericUpDown2.Value, numericUpDown1.Value);
- if (this.ValueChanged != null)
- {
- this.ValueChanged(this.numericUpDown2, e);
- }
- if (showTrackBar)
- {
- this.doubleSlidingTrackbar.SetRightSliderPos(maxValue);
- }
- }
- #region 组件设计器生成的代码
- private void InitializeLanguageText()
- {
- if(!DesignMode)
- this.label1.Text = PdnResources.GetString("Menu.Colorinterval.text") + ":";
- }
- /// <summary>
- /// 设计器支持所需的方法 - 不要修改
- /// 使用代码编辑器修改此方法的内容。
- /// </summary>
- private void InitializeComponent()
- {
- this.numericUpDown2 = new System.Windows.Forms.NumericUpDown();
- this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
- this.label1 = new System.Windows.Forms.Label();
- ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit();
- ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
- this.SuspendLayout();
- //
- // numericUpDown1
- //
- this.numericUpDown1.Location = new System.Drawing.Point(65, 1);
- this.numericUpDown1.Maximum = new decimal(new int[] {
- int.MaxValue,
- 0,
- 0,
- 0});
- this.numericUpDown1.Name = "numericUpDown1";
- this.numericUpDown1.Tag = "min";
- this.numericUpDown1.Size = new System.Drawing.Size(40, 21);
- this.numericUpDown1.TabIndex = 12;
- this.numericUpDown1.ValueChanged += new System.EventHandler(this.numericUpDown1_ValueChanged);
- //
- // numericUpDown2
- //
- this.numericUpDown2.Location = new System.Drawing.Point(110, 1);
- this.numericUpDown2.Maximum = new decimal(new int[] {
- int.MaxValue,
- 0,
- 0,
- 0});
- this.numericUpDown2.Name = "numericUpDown2";
- this.numericUpDown2.Tag = "max";
- this.numericUpDown2.Size = new System.Drawing.Size(40, 21);
- this.numericUpDown2.TabIndex = 13;
- this.numericUpDown2.ValueChanged += new System.EventHandler(this.numericUpDown2_ValueChanged);
- //
- // label1
- //
- this.label1.AutoSize = true;
- this.label1.Location = new System.Drawing.Point(1, 4);
- this.label1.Name = "label1";
- this.label1.Size = new System.Drawing.Size(65, 12);
- this.label1.TabIndex = 14;
- this.label1.Text = "颜色区间:";
-
- //
- // DecimalScopeControl
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.Controls.Add(this.numericUpDown2);
- this.Controls.Add(this.numericUpDown1);
-
- this.Controls.Add(this.label1);
- this.Name = "DecimalScopeControl";
- this.Size = new System.Drawing.Size(150, 22);
- ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit();
- ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
- this.ResumeLayout(false);
- this.PerformLayout();
- }
- #endregion
- public DoubleSlidingTrackbar doubleSlidingTrackbar;
- public System.Windows.Forms.NumericUpDown numericUpDown2;
- public System.Windows.Forms.NumericUpDown numericUpDown1;
- private System.Windows.Forms.Label label1;
- }
- }
|