Hi - I am using custom textboxes and I need to be able to set the Text on txb1 based on the Text of txb2. I have simplied my code to the following:
and the form code is:
So, when txb1 looses focus, if its Text is "fried", then it sets off txb2's ProcessAlert function. I had tried to change the value of txb2 Text in ProcessAlert function, but didnt work, so I tried to get it to raise an event instead, which then tries to set the Text property. However I still cant set txb2's Text property. The Text property seems to be set for the duration of the "life" of the Event handler. When I step through the forms controls within the Event handler, the changed Text value is there, but not outside of the Event handler.
Any suggestions???
Many thanks
Code:
Public Class customtextbox
Inherits TextBox
Public Event ControlReset()
Public Sub New(ByVal strP As String)
MyBase.New()
AddHandler customtextbox.ControlReset, AddressOf Me.test
End Sub
Public Sub test()
Me.Text = "chips" + Me.Name
End Sub
Public Sub ProcessAlert()
RaiseEvent ControlReset()
End Sub
Private Sub customtextbox_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LostFocus
Dim cT As Control
Dim cS As customtextbox
If Me.Name = "txb1" Then
If Me.Text = "fried" Then
For Each cT In frmTest.Controls
If cT.Name = "txb2" Then
cS = cT
Call cS.ProcessAlert()
End If
Next
End If
End If
End Sub
End Class
Code:
Public Class frmTest
Public Sub New()
InitializeComponent()
Dim txb1 As customtextbox
Dim txb2 As customtextbox
txb1 = New customtextbox("params for txb1")
txb1.Name = "txb1"
txb1.Location = New Point(10, 10)
txb1.Size = New Point(200, 20)
Me.Controls.Add(txb1)
txb2 = New customtextbox("params for txb2")
txb2.Name = "txb2"
txb2.Location = New Point(10, 30)
txb2.Size = New Point(200, 20)
Me.Controls.Add(txb2)
End Sub
End Class
Any suggestions???
Many thanks
Comment