2017-11-02 14 views
2

アクセラレータ機能を通常のButtonに適用するにはどうすればよいですか? (NumericUpDownコントロールのAccelerationプロパティのように)。下の画像では、ウィンドウの全体的なサイズの寸法を操作するコントロールがあることがわかりました。コントラストをNumericUpDownにするのではなく、そのままレイアウトを維持したいと考えています。NumericUpDownのアクセラレーション機能を通常のボタンに適用するには

たとえば、>>>ボタン(増分幅1インチ)では、ユーザーがボタンを押したままにしたときに対応するTextBoxに表示されている数値を加速したいと考えています。

私の初期の考えは、コントロールを継承および/またはラップし、後者の既存のプロパティを活用するカスタムButtonを作成することでした。しかし、ボタンが押し下げられた状態で保持されている間は、下にあるNumericUpDownコントロールで適切なイベント/プロパティを起動する必要があります。何か案は?ありがとう!

enter image description here

+2

いいえ、簡単には理解できません。自分自身でこの機能を実装する方法のインスピレーションが必要な場合は、[参照元](https://referencesource.microsoft.com/#System.Windows.Forms/winforms/Managed/System/WinForms/UpDownBase.cs)から開始することを検討してください。 、434558e770866e51) –

+0

参考に感謝します。 – Rhurac

答えて

1

多分Timerを追加しますか? VB.net:

Private mouseDownTimeElapsed As Integer = 0 

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick 
    'Increment the total time mouse has been depressed 
    mouseDownTimeElapsed += 50 
    'The following have the same effect as the NumericUpDownAcceleration objects 
    If mouseDownTimeElapsed > 2000 Then 
     IncrementOverallWidth(10) 
    ElseIf mouseDownTimeElapsed > 1000 Then 
     IncrementOverallWidth(3) 
    ElseIf mouseDownTimeElapsed > 500 Then 
     IncrementOverallWidth(1) 
    End If 
End Sub 

Private Sub Button2_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button2.MouseDown 
    'This check is necessary or a single click won't trigger an increment 
    If mouseDownTimeElapsed = 0 Then 
     IncrementOverallWidth(1) 
    End If 
    Timer1.Enabled = True 
    Timer1.Interval = 50 
    Timer1.Start() 
End Sub 

Private Sub Button2_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button2.MouseUp 
    Timer1.Stop() 
    'Reset the mouse down time to zero so the process can start over on next click 
    mouseDownTimeElapsed = 0 
End Sub 
関連する問題