tags:

views:

26

answers:

2

Hello Everyone

I have to use key down event on text box. Code for the event looks like this:

 Private Sub TextBox1_Keydown(ByVal sender As Object, ByVal e As
 System.Windows.Forms.KeyEventArgs) Handles textBox1.KeyDown   
 If e.KeyCode = keys.Enter Then
    MessageBox.Show("Hello")   
 End If
 End Sub

But it gives the following error:

Handles clause requires a WithEvents variable defined in the containing type  
or one of its base types. (BC30506) 

what does it mean? what i have to do for this?

Please help me out.

Thanks for your kind help.

A: 

Check if the textbox is defined with WithEvents keyword.
Example here.

EDIT: For your case, the definition should look like WithEvents TextBox1 as TextBox

shahkalpesh
I have declared like this :private withevents textBox1 as textboxI am getting the following error:'textBox1' is already declared as 'Private WithEvents textBox1 As System.Windows.Forms.TextBox' in this class. (BC30260) Thanks for ur kind reply. what is the problem?
shahkalpesh
when i remove this definition from the code, the above stated error comes i.e. Handles clause requires a WithEvents variable defined in the containing type or one of its base types. (BC30506).I am not able to figure it out where to define and what to define.Thanks a lot. help me.
shahkalpesh
It worked. Thanks a lot. Thanks once again.
A: 

On your {formname}.Designer.vb file check if you have something like this declared on it:

Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
hallie
I have done this but the following error comes'TextBox1' is already declared as 'Private textBox1 As System.Windows.Forms.TextBox' in this class. (BC30260)Help me. Thanks a lot.