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