How do we catch click event?
Have a small query in VB .Net.
How do we catch click event? Let me give example to make it clear
I have form1 with button in it. in form I m creating form2.
form1.vb
-----------
public sub button_click()
din frm2 as new form2
frm2.show()
end sub
In form2 I am creating button2.
form2.vb
----------
sub form2_load()
dim btn2 as new button2
me.controls.add(btn2)
end sub
When i run the program from1 with button will be displayed initially. when i click the button form2 with button will be created.
My requirement is when i click the button in the form2 I need to handle some function.
How do we do that? Since I am creating the button at the run time i don't have default function (Which we get when we create button in the from1.design and double click on it)
Sorry for the Long question, I just wanted to get the question clear..
Please can anyone provide me the solution for it??
Thanks
Prakash
Re: How do we catch click event?
'add this code where u create a new dynamic control dim cntrl as new button me.controls.add(cntrl) addhandler cntrl.click, addressof button2click private sub button2click(byval sender as object, byval e as system.eventargs) messagebox.show("button2click") end sub
Re: How do we catch click event?
Dim cntrl as new button me.controls.add(cntrl) 'add this code where you add new dynamic controls addhandler cntrl.click, addressof button2click private sub button2click(byval sender as object, byval e as system.eventargs) messagebox.show("button2click") end sub
Re: How do we catch click event?
Hi Monica,
Thanks for your reply.
I am not clear abt the addhandler
Actually i am a starter, so please can you make provide the code snippet??
addhandler cntrl.click,
addressof button2click
private sub button2click(byval sender as object, byval e as system.eventargs)
messagebox.show("button2click")
end sub
Can you edit in the correct form Please?
regards
Prakash
Re: How do we catch click event?
Hi Monica,
Thanks.. I could execute ur commands
Re: How do we catch click event?
hi
i have gone through your question
u r requirement is to provide functionality to button within form2 which u have created in runtime.
solution:we can use java script functiion to provide functionality to btn in frm2
by writing code within html page of that form
switch to html page
<input type="button" id="b2".... onclick="f1()">
using javascript write code for f1
fonction f1()
{
......
.....
}