- - PR -
Formでコントロールのフォーカス変更を検出する方法
1
投稿者 | 投稿内容 | ||||
---|---|---|---|---|---|
|
投稿日時: 2006-03-15 16:45
(xp pro VB.NET2003)
Form上でコンテナ内のコントロールも含めて、ActiveControlの変更を検出したいです。 OnActiveControlChangedなんていうのがあればよかったのですが・・・ --- クラス側 ------------------------------------------------------------ Public Class Focus Public Delegate Sub Handler(ByVal sender As Object) Private WithEvents m_ctl As Control Shared a_control As Control Public Event OnActiveControlChanged As Handler Public Sub New(ByVal ctl As Control) m_ctl = ctl End Sub Public Function init_decorator(ByVal m As Control) As Int32 Dim m_contents As New Collection m_contents.Add(New Focus(m)) If m.Controls.Count = 0 Then Return 0 Else For Each ctl As Control In m.Controls If init_decorator(ctl) > 0 Then End If Next End If End Function Private Sub m_txt_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles m_ctl.Enter RaiseEvent OnActiveControlChanged(sender) Debug.WriteLine("kita- " & CType(sender, Control).Name) End Sub End Class --- Form側 -------------------------------------------------------- (Loadイベント内) Dim aa As deco.Focus = New deco.Focus(Me) aa.init_decorator(Me) AddHandler aa.OnActiveControlChanged, AddressOf e1 (イベントトラップ) Private Sub e1(ByVal sender As Object) Debug.WriteLine("ok desuyo" & CType(sender, Control).Name) End Sub 上記コードですと、クラス内の debug.writeline は通るのですが、 Form側のイベントトラップ内の debug.writeline は通りません。 Form側のイベントを発生させるにはどうすればよいでしょうか? | ||||
|
投稿日時: 2006-03-15 16:58
UpdateDefaultButton メソッド。 ただし、取り扱い注意。 _________________ C# と VB.NET の入門サイト じゃんぬねっと日誌 | ||||
|
投稿日時: 2006-03-15 17:13
Protected Overrides Sub UpdateDefaultButton()
Debug.WriteLine(Me.ActiveControl.Name & " kitapo") MyBase.UpdateDefaultButton() End Sub 上記コードでできました。 ありがとうございます。 なんでこんなわかりにくい名前になってるんだろ | ||||
|
投稿日時: 2006-03-15 17:25
名前は適切ですよ。 「そのために用意されているものではないから」が正しいです。 _________________ C# と VB.NET の入門サイト じゃんぬねっと日誌 |
1