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:
and then this in the Load event of the form.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
Code:AccociateTextBoxEventHandler(Me)


Reply With Quote

