简体   繁体   English

选择鼠标/将焦点放在文本框VB.NET上时,突出显示窗体中的文本框

[英]Highlight textbox in Forms when mouse selected/focus on textbox VB.NET

I want to ask if how could I change a textbox color when I highlighted for each textbox in form controls. 我想问一下在窗体控件中为每个文本框突出显示时如何更改文本框的颜色。

For example if I have 50+ textbox, its really hard for me to code 50+ textbox each right? 例如,如果我有50多个文本框,那么我真的很难对每个50多个文本框进行编码吗?

So is there anyway I could set this in a single function? 所以无论如何我可以在一个函数中设置它?

Any help is appreciated. 任何帮助表示赞赏。

Thanks, 谢谢,

Alvin. 阿尔文

Just make a new class and inherit from textbox. 只需创建一个新类并从文本框继承即可。 Alter the events in your textbox class and use it instead of the normal textbox. 更改文本框类中的事件,并使用它代替普通文本框。

Public Class MTB
Inherits TextBox

     Private Sub MTB_GotFocus(sender As Object, e As EventArgs) Handles Me.GotFocus
           BackColor = Color.Aqua

     End Sub
End Class

After you rebuild the project, the MTB object will be waiting for you in the toolbox. 重建项目后,MTB对象将在工具箱中等待您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM