Results 1 to 7 of 7

Thread: Calling an control event

  1. #1

    Thread Starter
    Fanatic Member pvbangera's Avatar
    Join Date
    Sep 2001
    Location
    Mumbai, India
    Posts
    961

    Question Calling an control event

    Hi ppl

    I want to call an control event from my procedure or function.

    Say, I want to call a click event of CommandButton1. In VB6, it was very easy as there were no arguments to pass.

    But how to do it in VB.Net? Mean, how to pass the 'sender' and 'e' argument while calling the event?

    Pls guide

    Regards,

    Prakash

  2. #2
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Dublin (Ireland)
    Posts
    304
    Investigate Raise Events, if I am correct then the event hasn't necessarily occured through the keyboard but you still want to act as if it has.

    Not a solution but a response based on your posting.

  3. #3
    Fanatic Member VBCrazyCoder's Avatar
    Join Date
    Apr 2003
    Posts
    681
    Then do:
    VB Code:
    1. Private Sub SomeProcedure()
    2. 'Fire off the click event of CommandButton1
    3. CommandButton1.PerformClick()
    4. End Sub

  4. #4

    Thread Starter
    Fanatic Member pvbangera's Avatar
    Join Date
    Sep 2001
    Location
    Mumbai, India
    Posts
    961
    PerfromClick is there. But that can be used only for Click event.

    But what about other events?

  5. #5
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276
    Just declare the arguments and call the event passing the args.
    VB Code:
    1. Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
    2.     Dim s As System.Object
    3.     Dim ev As System.EventArgs
    4.  
    5.     Button1_MouseEnter(s, ev)
    6.  
    7. End Sub
    8.  
    9. Private Sub Button1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseEnter
    10.     MessageBox.Show("button1 mouse enter")
    11. End Sub

  6. #6
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    You don't have to declare anything , like this :
    VB Code:
    1. Button1_Click(sender, e)

    or

    VB Code:
    1. Button1_Click(Me, e)

  7. #7
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Yes sender is generally the item that raised the event (in this cause the button) and you can pass Nothing or EventArgs.Empty if you don't need that parameter.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width