locked
Textbox

    Question

  • I've got these 9 textboxes - When the text is changed it has this code

    DONEXTSTEP()

    And it does that Private Sub. How can that next Sub know what textbox sent it?

    Tuesday, December 12, 2006 7:51 PM

Answers

  • Hi,

    TextBox's TextChanged event has a sender parameter. This parameter tells you which control raised the event. To use it, first cast it to the TextBox type:

    Private Sub TextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged, TextBox2.TextChanged, TextBox3.TextChanged
       
    Dim textBox As TextBox = DirectCast(sender, TextBox)
       
    DoNextStep(textBox)
    End Sub

    Andrej

    Tuesday, December 12, 2006 8:13 PM
  • AliQ,
     
    Because of subtle differences between Microsoft Visual Basic 6.0 and Visual Basic .NET, some events may produce unexpected results when a Windows Form is loaded. Problems can arise if the code that is used in one event relies on the values or the objects that are set or initiated in another event.

    For example, if you use the Initialize event on the form to change the Text property of a TextBox control in Visual Basic 6.0, the Change event of the TextBox is fired one time. In Visual Basic .NET, the same procedure fires the TextChange event according to the following conditions:
     
    If the Text property of a TextBox control is blank at design time, the TextChange event is fired one time.

    If you set the Text property of a TextBox control to a value at design time, the TextChange event is fired twice.

    More importantly, the Text event is fired after the Form_Load event in Visual Basic 6.0 and before the Form1_Load event in Visual Basic .NET.
    Friday, December 15, 2006 7:46 AM

All replies

  • Hi,

    TextBox's TextChanged event has a sender parameter. This parameter tells you which control raised the event. To use it, first cast it to the TextBox type:

    Private Sub TextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged, TextBox2.TextChanged, TextBox3.TextChanged
       
    Dim textBox As TextBox = DirectCast(sender, TextBox)
       
    DoNextStep(textBox)
    End Sub

    Andrej

    Tuesday, December 12, 2006 8:13 PM
  • AliQ,
     
    Because of subtle differences between Microsoft Visual Basic 6.0 and Visual Basic .NET, some events may produce unexpected results when a Windows Form is loaded. Problems can arise if the code that is used in one event relies on the values or the objects that are set or initiated in another event.

    For example, if you use the Initialize event on the form to change the Text property of a TextBox control in Visual Basic 6.0, the Change event of the TextBox is fired one time. In Visual Basic .NET, the same procedure fires the TextChange event according to the following conditions:
     
    If the Text property of a TextBox control is blank at design time, the TextChange event is fired one time.

    If you set the Text property of a TextBox control to a value at design time, the TextChange event is fired twice.

    More importantly, the Text event is fired after the Form_Load event in Visual Basic 6.0 and before the Form1_Load event in Visual Basic .NET.
    Friday, December 15, 2006 7:46 AM
  • AliQ,

    After the explanation and the Andrej Tozan's answers, I think you have got the exact solution in your project. I hope that can give some help and if you have any other problems, please post here.

    Friday, December 22, 2006 2:30 AM