いくつかのnumreicUpDownコントロールを備えたWinFormがありますが、値がインクリメントまたはデクリメントされているかどうかを知りたいです。コントロールは、両方の状況で変更されたイベント値を起動します。私が理解できる限り、プログラムはUpButtonメソッドとDownButtonメソッドを呼び出します。値がどのように変更されたかを知る他の方法はありますか、またはこのメソッドでこれを行う必要がありますか(イベントを起動したり、Up-Down-Buttonでコードを実装したりするなど)
4615 次
2 に答える
3
これを行うための標準的な方法はありません。古い値を覚えて、新しい値と比較することをお勧めします
decimal oldValue;
private void ValueChanged(object sender, EventArgs e)
{
if (numericUpDown.Value > oldValue)
{
}
else
{
}
oldValue = numericUpDown.Value;
}
于 2012-09-24T07:46:49.663 に答える
1
これらのUpButtonメソッドとDownButtonメソッドをオーバーライドする独自のコントロールを作成します。
using System.Windows.Forms;
public class EnhancedNUD : NumericUpDown
{
public event EventHandler BeforeUpButtoning;
public event EventHandler BeforeDownButtoning;
public event EventHandler AfterUpButtoning;
public event EventHandler AfterDownButtoning;
public override void UpButton()
{
if (BeforeUpButtoning != null) BeforeUpButtoning.Invoke(this, new EventArgs());
//Do what you want here...
//Or comment out the line below and do your own thing
base.UpButton();
if (AfterUpButtoning != null) AfterUpButtoning.Invoke(this, new EventArgs());
}
public override void DownButton()
{
if (BeforeDownButtoning != null) BeforeDownButtoning.Invoke(this, new EventArgs());
//Do what you want here...
//Or comment out the line below and do your own thing
base.DownButton();
if (AfterDownButtoning != null) AfterDownButtoning.Invoke(this, new EventArgs());
}
}
次に、フォームにコントロールを実装するときに、いくつかのイベントをフックして、どのボタンがクリックされたか、またはキー(上/下)が押されたかを通知できます。
于 2016-12-16T22:02:18.497 に答える