textBox : add TextChanged events or other events

abys

New Member
Here is a library code source build with sharpdevelop, you can add textChanged events to all you textbox controls :

For #Develop :

Imports System.Windows.Forms
Imports System.Drawing

Public Class txtBox
Implements IDisposable 'Inherit from IDisposable if you need Basic4ppc to free resources when the application is closed.
Private WithEvents myControl As System.Windows.Forms.TextBox'The "real" object.
Public Event TextChanged As EventHandler 'The event handler name must match the event name.
Private eventObject() As Object 'One object[] for each event (one event here).

Sub New( ByVal frm as Form, ByVal txtBox As Control)
Dim ctrl As Windows.Forms.Control
For Each ctrl In frm.Controls
If (ctrl.Name = txtBox.Name) Then
eventObject = New Object() {Me, "TextChanged"}
AddHandler txtBox.TextChanged, AddressOf myControl_TextChanged
Exit Sub
End If
Next
msgbox ("Not Found")
End Sub

Private Sub myControl_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles myControl.TextChanged
RaiseEvent TextChanged(eventObject, Nothing)
End Sub

Public Sub Dispose() Implements System.IDisposable.Dispose
If Not myControl Is Nothing Then
myControl.Dispose()
End If
End Sub
End Class


For Basic4PPC :

Sub App_Start
Form1.Show
sb.New1(Form1.Name,txt.Name)
sb.New1(Form1.Name,cmbDown.Name)
End Sub

Sub sb_TextChanged
Msgbox (txt.Text)
End Sub
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Thank you for sharing.

This could also be done with the Door library (example from the manual):
B4X:
[LEFT][FONT=Courier New][COLOR=#008000]'obj is an Object, TextBox1ChangedEvent is an Event.[/COLOR][/FONT]
[FONT=Courier New][COLOR=#0000ff]Sub [/COLOR][/FONT][FONT=Courier New]App_Start[/FONT]
[FONT=Courier New]    Form1.Show[/FONT]
[FONT=Courier New]    obj.New1(false)[/FONT]
[FONT=Courier New]    obj.FromControl([/FONT][FONT=Courier New][COLOR=#800000]"textbox1"[/COLOR][/FONT][FONT=Courier New])[/FONT]
[FONT=Courier New]    TextBox1ChangedEvent.New1( obj.Value,[/FONT][FONT=Courier New][COLOR=#800000]"TextChanged"[/COLOR][/FONT][FONT=Courier New])[/FONT]
[FONT=Courier New][COLOR=#0000ff]End Sub[/COLOR][/FONT]

[FONT=Courier New][COLOR=#0000ff]Sub [/COLOR][/FONT][FONT=Courier New]TextBox1ChangedEvent_NewEvent[/FONT]
[FONT=Courier New]    form1.Text = textbox1.Text[/FONT]
[FONT=Courier New][COLOR=#0000ff]End Sub[/COLOR][/FONT][/LEFT]
 
Top