Show current textbox descr on statusbar
Say you have a form and on it you have 3 TextBox's. Now you want to color the textbox's and at the same time show a discription on the status bar of your application the discription of the TextBox (I use the ToolTip.Text).
What usualy is done is the same code for all textbox controls. Now, say you have a form that has 300 textbox's on it. What do you do? Well I have created the following code to overcome lots of line of code.
place this in a module:
Code:
Private Sub TextBox_Enter(ByVal Sender As Object, ByVal e As System.EventArgs)
Sender.BackColor = Color.LemonChiffon
fSysStartUp.StatusStrip1.Items("ToolStripStatusLabel1").Text = Sender.FindForm.ToolTip1.GetToolTip(Sender).ToString()
End Sub
Private Sub TextBox_Leave(ByVal Sender As Object, ByVal e As System.EventArgs)
Sender.BackColor = Color.FromKnownColor(KnownColor.Window)
End Sub
Public Sub AccociateTextBoxEventHandler(ByVal myControlIN As Control)
For Each myControl As Control In myControlIN.Controls
AccociateTextBoxEventHandler(myControl)
Dim AllTextBoxes As TextBox
If TypeOf myControl Is TextBox Then
AllTextBoxes = myControl
AddHandler AllTextBoxes.Enter, AddressOf TextBox_Enter
AddHandler AllTextBoxes.Leave, AddressOf TextBox_Leave
End If
Next
End Sub
and then this in the Load event of the form.
Code:
AccociateTextBoxEventHandler(Me)
Re: Show current textbox descr on statusbar
The VB.NET forum is for asking questions about VB.NET. If you want to share code snippets or the like with others then you should post them in the VB.NET CodeBank forum. I have asked the mods to move this thread.
With regards to your code, I have one issue. I strongly recommend that everyone turns Option Strict On for every project and only turns it Off in code files that specifically need to make use of late-binding. Your code uses late-binding so you obviously have Option Strict Off. I'd strongly suggest turning it On and casting as required.
Also, please use the Code or VBCode buttons to wrap your code snippets in formatting tags to make them easier to read.
Nice job apart from that though.
Re: Show current textbox descr on statusbar
Thread moved from the 'VB.Net' forum to the 'CodeBank VB.Net' forum (thanks for letting us know jmcilhinney :thumb: )