将2个轨道栏绑定到一个抛出ArgumentOutOfRangeException的int

时间:2015-01-20 13:25:17

标签: c# winforms data-binding trackbar

我有一个看起来像Notepad ++上的查找表单的表单。有一个带有2个选项卡的tabControl。每个标签都有一个轨迹栏,我希望每个轨迹栏的值都相同,如果有人移动轨迹栏1,那么轨迹栏2会自动移动。

查找表单构造函数

private NotifyInt transparencyPercent;
public FindForm(string text, Action<String> findTextAction)
{
    InitializeComponent();
    transparencyPercent = new NotifyInt(85);
    this.findTransparencyTrack.DataBindings.Add("Value",transparencyPercent, "IntValue");
    this.findReplaceTransparencyTrack.DataBindings.Add("Value",transparencyPercent, "IntValue");

}

NotifyInt类

public class NotifyInt : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;

    public NotifyInt(int initialValue)
    {
        this.IntValue = initialValue;
        if (PropertyChanged != null)
            PropertyChanged(this, new PropertyChangedEventArgs("IntValue"));
    }
    public int IntValue
    {
        get
        {
            return this.intValue;

        }
        set
        {
            Console.WriteLine("Setting: " + value);
            this.intValue = value;
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs("IntValue"));

        }
    }
}

设计师设置

// 
// findTransparencyTrack
// 
this.findTransparencyTrack.AutoSize = false;
this.findTransparencyTrack.BackColor = System.Drawing.SystemColors.ButtonHighlight;
this.findTransparencyTrack.Location = new System.Drawing.Point(8, 52);
this.findTransparencyTrack.Maximum = 100;
this.findTransparencyTrack.Minimum = 5;
this.findTransparencyTrack.Name = "findTransparencyTrack";
this.findTransparencyTrack.Size = new System.Drawing.Size(80, 13);
this.findTransparencyTrack.TabIndex = 2;
this.findTransparencyTrack.TickStyle = System.Windows.Forms.TickStyle.None;
this.findTransparencyTrack.Value = 5;
this.findTransparencyTrack.ValueChanged += new    System.EventHandler(this.findTransparencyTrack_ValueChanged);
// 
// findReplaceTransparencyTrack
// 
this.findReplaceTransparencyTrack.AutoSize = false;    
this.findReplaceTransparencyTrack.BackColor = System.Drawing.SystemColors.ButtonHighlight;
this.findReplaceTransparencyTrack.Location = new System.Drawing.Point(8, 52);
this.findReplaceTransparencyTrack.Maximum = 100;
this.findReplaceTransparencyTrack.Minimum = 5;
this.findReplaceTransparencyTrack.Name = "findReplaceTransparencyTrack";
this.findReplaceTransparencyTrack.Size = new System.Drawing.Size(80, 13);
this.findReplaceTransparencyTrack.TabIndex = 2;
this.findReplaceTransparencyTrack.TickStyle = System.Windows.Forms.TickStyle.None;
this.findReplaceTransparencyTrack.Value = 5;
this.findReplaceTransparencyTrack.ValueChanged += new System.EventHandler(this.findReplaceTransparencyTrack_ValueChanged);

如果我打开表单,请在查找选项卡上滑动轨迹栏并将焦点放在另一个控件上Visual Studio弹出错误说

  

类型&#39; System.ArgumentOutOfRangeException&#39;的例外情况发生在   System.Windows.Forms.dll但未在用户代码中处理   信息:&#39; 0&#39;的价值对于&#39;值&#39;无效。 &#39;值&#39;应该   介于&#39;最低&#39;之间和&#39;最大&#39;。

在NotifyInt设置器末尾的括号上,即使输出仅显示值为85&amp; 75。 环境:85 设置:75

如果我打开表单,请单击第二个选项卡然后返回第一个选项卡并移动第一个选项卡上的滑块一切正常并且没有错误。

0 个答案:

没有答案