RaiseEvent

  • Thread starter steven_licciardinnoossppaamm
  • Start date
S

steven_licciardinnoossppaamm

Hello,

I am creating events textboxes on the fly within my code
and would like to capture the keypress events for each
textbox. In c# I would use :

this.textBox1.KeyPress += new
System.Windows.Forms.KeyPressEventHandler
(this.textBox1_KeyPress);

where I create the textbox. However if I use vb.net and
the following :

tb.KeyPress += New
System.Windows.Forms.KeyPressEventHandler(AddressOf
Me.textBox1_KeyPress)

I get an error telling me that KeyPress is an event and
cannot be used direct.....

Can anyone please advise.

Thanks,

Steven
 
M

marcmc

just dbl. click the control on your form.
it will default to the click event.
the from the 2nd combo box just above your screen choose
the keypress event.

Private Sub TextBox2_KeyPress(ByVal sender As Object,
ByVal e As System.Windows.Forms.KeyPressEventArgs)
Handles TextBox2.KeyPress
' // some event code here
End Sub
 
S

steven_licciardinnoossppaamm

Actually I wanted to be able to generate the event
handlers from within the code, as I was generating the
textboxes there at runtime, rather than design time.
Anyway I've just managed to fix it using :

AddHandler Me.tb.KeyPress, AddressOf Me.tb_KeyPress

Thanks,

Steven
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top