comp • gb.form • buttonbox • .change

Event ButtonBox.Change (gb.form)

Event Change ( )

Raised when the text of the control changes.

This event is raised for each letter which is typed in, or whenever the program writes to the Text property.

Examples

Public Sub TextBox1_Change()

  If TextBox1.Text = "gray" Then PictureBox1.Background = &H707070&

End

If you want to use this event to modify the Text in the same TextBox, then this event handler is raised again.

To prevent a stack overflow:

    Examples

    Public Sub TextBox1_Change()
    
      If TextBox1.Text = "gray" Or TextBox1.Text = "grey" Then
        Object.Lock(TextBox1)
        TextBox1.Text = "grey"
        Object.Unlock(TextBox1)
      Endif
    
    End
    

  • Or use a Boolean semaphore to prevent a second entry when the event is raised by the event handler instead by manual input.

    Public bRefreshing As Boolean
    
    Public Sub TextBox1_Change()
    
      If bRefreshing Then Return
    
      bRefreshing = True
    
      If TextBox1.Text = "gray" Or TextBox1.Text = "grey" Then
        TextBox1.Text = "grey"
      Endif
    
      bRefreshing = False
    
    End