I have a form with the NumericUpDown
and the ToolStripButton
.
In the NumericUpDown
s ValueChanged
event handler the value of some object instance is changed.
In the ToolStripButton
s Click
event handler the object instance is saved.
Now the problem is that if I rewrite the value in the NumericUpDown
and then click on the ToolStripButton
to save the state the ToolStripButton
s Click
event is fired before the NumericUpDown
s ValueChanged
event so I first save the instance and after that I changed it.
public partial class Form2 : Form
{
private Foo _foo = new Foo();
public Form2()
{
InitializeComponent();
}
private void NumericUpDown1_ValueChanged(object sender, EventArgs e)
{
_foo.Value = numericUpDown1.Value;
}
private void ToolStripButton1_Click(object sender, EventArgs e)
{
_foo.Save();
}
private class Foo
{
public decimal Value { get; set; }
public void Save()
{
//Save the value...
}
}
}
What is the best way to solve this?
Those events are fired in the correct order if I use the Button
control, but not if I use the ToolStripButton
control.