Event TextBox.Change (gb.qt4)

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