I have solved this problem before. Let's take the NumericUpDown control as an illustrative example.
First, create a new control (call it MyNumericUpDown) that inherits from the NumericUpDown. Create overrides for the UpButton, DownButton, and OnLostFocus methods. Also create a public method for setting the value of the control programmatically. Create an enum type called 'ValueChangedType' that has 4 different values called TextEdit, UpButton, DownButton, and Programmatic (or call them whatever you like). Also create a property called ChangedType of type ValueChangedType. Here is what the class looks like.
public partial class MyNumericUpDown : NumericUpDown
{
public enum ValueChangedType
{
TextEdit,
UpButton,
DownButton,
Programmatic
}
public ValueChangedType ChangedType = ValueChangedType.Programmatic;
public MyNumericUpDown()
{
InitializeComponent();
}
public override void UpButton()
{
this.ChangedType = ValueChangedType.UpButton;
base.UpButton();
}
public override void DownButton()
{
this.ChangedType = ValueChangedType.DownButton;
base.DownButton();
}
protected override void OnLostFocus(EventArgs e)
{
this.ChangedType = ValueChangedType.TextEdit;
base.OnLostFocus(e);
}
public void SetValue(decimal val)
{
this.ChangedType = ValueChangedType.Programmatic;
this.Value = val;
}
}
Now, in your form, create a MyNumericUpDown control (call it 'myNUD'). In the ValueChanged event handler for the control, you can get the value of the ChangedType property, and do something with it:
private void myNUD_ValueChanged(object sender, EventArgs e)
{
MyNumericUpDown nud = sender as MyNumericUpDown;
var myChangedType = nud.ChangedType;
/* do something */
}