当焦点从一个控件转移到另一个控件时,是否有任何事件触发? [英] Is there is any event fires when focus chenaged from one control to another control?

查看:198
本文介绍了当焦点从一个控件转移到另一个控件时,是否有任何事件触发?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我在表格中有100个控件。我想运行一些代码,当焦点从一个控件更改为vb.net形式的另一个控件。是否有任何事件?

Hi,

I am having 100''s of controls in a form. I want to run some code, when focus changed from one control to another control in vb.net form. Is there any event?

推荐答案

是,请参阅: MSDN上的Control.LostFocus事件 [ ^ ]


使用一个函数(或Sub)处理LostFocus事件所有控件显示在下面

Just Handle LostFocus Event All Control Using One Function (or Sub) as Displayed Below
Private Sub LostFocus(ByVal sender as System.Object, e As EventArgs) Handles _
Control1.LostFocus, Control2.LostFocus, Control3.LostFocus, Control4.LostFocus, _
Control5.LostFocus, Control6.LostFocus, Control7.LostFocus, Control8.LostFocus, _
Control9.LostFocus, Control10.LostFocus

'Now Use sender Parameter to Identify Which Control Lost it's Focus
Select Case sender.Name
case Control1.Name
    ' Write Code
case Control2.Name
    ' Write Code
case Control3.Name
    ' Write Code
case Control4.Name
    ' Write Code
case Control5.Name
    ' Write Code
case Control6.Name
    ' Write Code
case Control7.Name
    ' Write Code
case Control8.Name
    ' Write Code
case Control9.Name
    ' Write Code
case Control10.Name
    ' Write Code
case Else
    ' Write Code Here if Necessary

End Select

End Sub


For Each ctrl As Control in Me.Controls

AddHandler ctrl.Enter,AddressOf ControlFocusChanged

下一页





i在controlfocuschanged事件中编写我的代码。





感谢您的建议。
For Each ctrl As Control In Me.Controls
AddHandler ctrl.Enter, AddressOf ControlFocusChanged
Next


i write my code in controlfocuschanged event.


Thanks for your suggestions.


这篇关于当焦点从一个控件转移到另一个控件时,是否有任何事件触发?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆