Results 1 to 6 of 6

Thread: How do we catch click event?

  1. #1
    Contributing Member
    Join Date
    Apr 2007
    Answers
    41

    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


  2. #2
    Junior Member
    Join Date
    May 2006
    Answers
    4

    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


  3. #3
    Junior Member
    Join Date
    May 2006
    Answers
    4

    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


  4. #4
    Contributing Member
    Join Date
    Apr 2007
    Answers
    41

    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


  5. #5
    Contributing Member
    Join Date
    Apr 2007
    Answers
    41

    Re: How do we catch click event?

    Hi Monica,

    Thanks.. I could execute ur commands


  6. #6
    Junior Member
    Join Date
    Apr 2007
    Answers
    1

    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()
    {
    ......
    .....
    }


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact