I have a Form that looks like the Find form on Notepad++. There is a tabControl with 2 tabs. Each tab has a trackbar and I want the value of each trackbar to be the same, if somebody moves trackbar1 then trackbar2 moves automatically.
Find form constructor
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 class
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"));
}
}
}
Designer Settings
//
// 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);
If I open the form, slide the trackbar on the find tab and focus on another control Visual studio pops up an error saying
An exception of type 'System.ArgumentOutOfRangeException' occurred in System.Windows.Forms.dll but was not handled in user code Additional information: Value of '0' is not valid for 'Value'. 'Value' should be between 'Minimum' and 'Maximum'.
on the bracket at the end of the NotifyInt setter even though the output only shows the value to be 85 & 75. Setting: 85 Setting: 75
If I open the form, click on the second tab and then back to the first tab and move the slider on the first tab everything is fine and there are no errors.