Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. call the click event of a button

call the click event of a button

Scheduled Pinned Locked Moved Visual Basic
csharphelpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jlawren7
    wrote on last edited by
    #1

    here's te deal i have a form that has 2 buttons on it. i need to call the buttons click event from a different form in order to run the event i would just put the code into the form_load event but the form has a duel purpose so i can't do this. so in VB.NET, how do we call the click event form a different form i have tried the performclick() and this doesn't seem to work . here is a sample of code Private Sub EnterBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles EnterBtn.Click ' these next 2 lines remove the unwanted characters from the ' beginning and end of the card value in this case, the card ' values are 4 numbers delimited with a ; at the beginning ' and a ? at the end txtPassID.Text = txtPassID.Text.Remove(0, 1) txtPassID.Text = txtPassID.Text.Remove(4, 1) '********************************************************************** CIfrm.txtPassIdSearch.Text = txtPassID.Text CIfrm.SearchIDBtn.PerformClick()<-- not performing as it should CIfrm.ShowDialog(Me) Me.Close() End Sub i have to different searches being performed depending on what form the user uses. any help would be great Help is great only if you ask correctly :)

    T 1 Reply Last reply
    0
    • J jlawren7

      here's te deal i have a form that has 2 buttons on it. i need to call the buttons click event from a different form in order to run the event i would just put the code into the form_load event but the form has a duel purpose so i can't do this. so in VB.NET, how do we call the click event form a different form i have tried the performclick() and this doesn't seem to work . here is a sample of code Private Sub EnterBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles EnterBtn.Click ' these next 2 lines remove the unwanted characters from the ' beginning and end of the card value in this case, the card ' values are 4 numbers delimited with a ; at the beginning ' and a ? at the end txtPassID.Text = txtPassID.Text.Remove(0, 1) txtPassID.Text = txtPassID.Text.Remove(4, 1) '********************************************************************** CIfrm.txtPassIdSearch.Text = txtPassID.Text CIfrm.SearchIDBtn.PerformClick()<-- not performing as it should CIfrm.ShowDialog(Me) Me.Close() End Sub i have to different searches being performed depending on what form the user uses. any help would be great Help is great only if you ask correctly :)

      T Offline
      T Offline
      Tom John
      wrote on last edited by
      #2

      You need to make the event handler method for the button click on Form2 public and within it check what control it is handling: Public Sub Search(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click If sender.GetType Is GetType(Form1) Then MsgBox("Button Called By Form 1") ElseIf sender Is GetType(Button) Then MsgBox("Button Called By Button") End If End Sub Then from the other form you can call this method in the load handler: Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim form1Instance As New Form1 'Only if you don't have another instance form1Instance.Search(sender, e) End Sub Hope this helps, although maybe you want to rethink your design a bit though and have a another class that performs the search that each form could access independently: Public Class Search Public Shared Sub DoSearch(ByVal sender As Object, ByVal e As EventArgs) If sender.GetType Is GetType(Form1) Then MsgBox("Button Called By Form 1") ElseIf sender Is GetType(Button) Then MsgBox("Button Called By Button") End If End Sub End Class You could then call this from anywhere without even creating an instance of the Search class using: Public Sub Search(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click Search.DoSearch(sender, e) End Sub Cheers Tom

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups