TextBox BackColor更改

编程入门 行业动态 更新时间:2024-10-11 21:24:37
本文介绍了TextBox BackColor更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

亲爱的, 我做了一个项目。它差不多完成了。现在提出查询,当TextBox GotFocus时,它的背面颜色应该被改变,当它丢失时,它会变得正常。 表格中有更多TextBox。是否有任何编码可以解决它而不会一个接一个地打扰? 请回复...

Dear All, I have made a project. It is almost completed. Now query is raised that when TextBox GotFocus, its back color should be changed and when it lostFocus, it shuld be normal. Many more TextBox are on form. Is there any coding to resolve it without disturbing to one-by-one ? Please reply...

推荐答案

在VB.NET中,您可以使用单个函数处理多个事件 - 您不必双击每个文本框或类似的东西:-) 我创建了一个包含6个文本框的表单(TextBox1,TextBox2等),然后使用这两个函数来处理所有的Enter(GotFocus)和Leave(LostFocus)事件 In VB.NET you can have a single function handle several events - you don't have to double-click on every text box or anything like that :-) I created a form with 6 textboxes on it (TextBox1, TextBox2 etc) then used these two functions to handle all of the Enter (GotFocus) and Leave (LostFocus) events Private Sub TextBoxX_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.Enter, TextBox2.Enter, TextBox3.Enter, TextBox4.Enter, TextBox5.Enter, TextBox6.Enter Dim tb As TextBox = sender tb.BackColor = Color.Tomato End Sub Private Sub TextBoxX_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.Leave, TextBox2.Leave, TextBox3.Leave, TextBox4.Leave, TextBox5.Leave, TextBox6.Leave Dim tb As TextBox = sender tb.BackColor = Color.Violet End Sub

如果您需要更多,那么只需在列表末尾添加文本框事件例如

If you need more then just add the text box events at the end of the list e.g.

Handles TextBox1.Enter, TextBox2.Enter, TextBox3.Enter, TextBox4.Enter, TextBox5.Enter, TextBox6.Enter ,TextBox7.Enter

如果您对可以添加的处理程序数量达到任何限制,那么只需创建另一对调用这些处理程序的处理程序,例如

If you hit any limits on the number of handlers you can add then just create another pair of handlers that call these ones e.g.

Private Sub T6_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox8.Leave TextBoxX_Leave(sender, e) End Sub Private Sub T8_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox8.Enter TextBoxX_Enter(sender, e) End Sub

检查这个边框颜色的小提琴只是为了背景颜色(如果这是一个网络应用程序) 小提琴 Check this fiddle it is for border color just make it for backcolor (if this is a web app) Fiddle

试试这个如果是桌面应用程序 Try this if it is a desktop application Private Sub Text_GotFocus() Me.Text.BackStyle = normal End Sub Private Sub Text_LostFocus() Me.Text.BackStyle = Transparent End Sub

更多推荐

TextBox BackColor更改

本文发布于:2023-11-06 08:49:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1563227.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:TextBox   BackColor

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!