locked
Button Click event and textbox.focus() not working RRS feed

  • Question

  • Hello MSDN Forum...On my form1.vb [Design], I have a button control that the click event is to show form2 and focus textbox1. I used following code:

    Form2.Show()

    form2.Textbox1.focus()

    It worked well initially but after build and publish it stopped working!! Form2 will show but textbox1 ain't focused! Secondly, I have another button on form2 to show form3 but the click will not show anything! Somebody help me out.


    Laborare est Orare...

    Tuesday, December 3, 2013 6:42 PM

Answers

  • Hi,

    For your question, I can't see more details of your Form2, so I just created a sample:

    In Form1, there is a button to open Form2:

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim form As Form2 = New Form2()
            form.Show()
            form.TextBox1.Focus()
        End Sub

    In Form2, there are some TextBox controls:


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, December 4, 2013 11:33 AM
  • Hi,

     You could also set the TabIndex property of the TextBox to 0 and set the TabStop property to True. Then make sure that there is not another control on the form that has the TabIndex set to 0 also.

    Wednesday, December 4, 2013 11:40 AM

All replies

  • Hi,

    For your question, I can't see more details of your Form2, so I just created a sample:

    In Form1, there is a button to open Form2:

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim form As Form2 = New Form2()
            form.Show()
            form.TextBox1.Focus()
        End Sub

    In Form2, there are some TextBox controls:


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, December 4, 2013 11:33 AM
  • Hi,

     You could also set the TabIndex property of the TextBox to 0 and set the TabStop property to True. Then make sure that there is not another control on the form that has the TabIndex set to 0 also.

    Wednesday, December 4, 2013 11:40 AM
  • Also what is the code you use in the form2 button to open form3 ?

    Wednesday, December 4, 2013 12:08 PM
  • Simply place the Textbox focus in the activated event of form2


    Success
    Cor

    Wednesday, December 4, 2013 12:28 PM