samedi 18 avril 2015

VB ActiveControl property when used in an event handler

I am currently trying to change the active control of my form when a particular event handler is activated. The eventhandler will first make changes to the variable before selecting another control.


However, the changes to the variable are always applied twice. After a series of tests,i discovered that the event handler is activated twice when the activecontrol property is present. The simplified version of the code are as follows,



Dim Yvar As Double = 0


Private Sub Textbox1_Enter(sender As Object, e As EventArgs) Handles TextBox1.Enter

Yvar += 1
ActiveControl = Nothing
Label2.Text = Yvar

End Sub


having tested the above code, the value of yvar will always increase by 2. I have tried using other methods (i.e control.select / control.focus) but nothing seems to work.


any help here will be greatly appreciated !


Aucun commentaire:

Enregistrer un commentaire