私はこのフォームの5つのテキストボックスに書き込むために+ 50個のコントロールとキー数値スクリーンを持つフォームを持っています。最後のフォーカスのテキストボックス
私は、キー数値の画面を使用して、これらのテキストボックスに書くためにこのコードを使用しています:
Private Sub bt0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt0.Click, bt1.Click, bt2.Click, bt3.Click, bt4.Click, bt5.Click, bt6.Click, bt7.Click, bt8.Click, bt9.Click, btDec.Click
If TypeOf sender Is DevExpress.XtraEditors.SimpleButton Then
txtRefe.Focus()
SendKeys.Send(CType(sender, DevExpress.XtraEditors.SimpleButton).Text)
End If
End Sub
問題は:私は数字ボタン
に触れる前に、フォーカスを持っていたこれら5テキストボックスのかを知る必要があり私は最後のフォーカスを見つけるために、この記事Find out the control with last focusからこのコードを見てきました:
Private _focusedControl As Control
Private Sub TextBox_GotFocus(ByVal sender As Object, ByVal e As EventArgs)
_focusedControl = DirectCast(sender, Control)
End Sub
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
If _focusedControl IsNot Nothing Then
'Change the color of the previously-focused textbox
_focusedControl.BackColor = Color.Red
End If
End Sub
しかし、どのように私は+ 50コントロール(多くの種類のコントロール:ボタン、チェックボックス、コンボ、テキストボックスなど)を持つフォームでそれを行うのですか?
解決策はすべて(+ 50個のコントロール)をキャッチすることをお勧めしますか? – aco
@yae:はい。他の唯一のオプションは、Windowsメッセージを傍受することですが、それははるかに複雑になります。 – SLaks