VB.NET, C#, PowerShellを使用しているエンジニアのためのサイト。
基本的な使用方法から開発で役立つTipsまで幅広く取り扱っています。
<< 前のTips 次のTips >>
[PageDown][PageUp]コントロールで値を変更できるようにしたサンプルを掲載します。NumericUpDownコントロールのKeyDownイベントの中で、押されたキーを判断し移動量を変更しています。
private const int intStep = 5; //[PageDown][PageUp]での移動量 private void Form1_Load(object sender, System.EventArgs e) { //初期値を0にする numericUpDown1.Value = 0; //矢印ボタンクリック時の移動量を1とする numericUpDown1.Increment = 1; //最小値を指定する numericUpDown1.Minimum = -100; //最大値を指定する numericUpDown1.Maximum = 100; } private void numericUpDown1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { //[PageUp]キー押下時 if ( e.KeyCode == Keys.PageUp ) { //移動量がMaxmum値を超えないか? if ( numericUpDown1.Maximum - intStep >= numericUpDown1.Value ) { //Maxmum値を超えないので値変更する numericUpDown1.Value = numericUpDown1.Value + intStep; } } //[PageDown]キー押下時 else if ( e.KeyCode == Keys.PageDown ) { //移動量がMinimum値を超えないか? if ( numericUpDown1.Minimum + intStep <= numericUpDown1.Value ) { //Minimum値を超えないので値変更する numericUpDown1.Value = numericUpDown1.Value - intStep; } } }
<< 前のTips 次のTips >>