using System;
using System.Windows.Forms;
namespace PaintDotNet.CustomControl
{
public partial class DecimalScopeControl : BaseUserControl
{
///
/// 参数的index
///
public int paramIndex;
///
/// 参数值改变
///
public event EventHandler ValueChanged;
///
/// 默认不显示进度条
///
private bool showTrackBar = false;
///
/// 十进制位数
///
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;
}
}
///
/// 如果numericUpDown2的最大值发生变化
/// 则初始化数据和拖动条数据
///
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;
}
}
///
/// 默认构造函数
///
public DecimalScopeControl()
{
InitializeComponent();
InitializeLanguageText();
}
///
/// 用于修改文字
///
///
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();
}
///
/// 用于隐藏文字Label,并修改numericUpDown位置
///
///
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") + ":";
}
///
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
///
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;
}
}