Button event

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Art

    Button event

    Hi,

    I've got a main module that instantiates a form and then does form.showdialog .

    The form has a button. I want the main module to respond to a click event
    from the button. I'm having trouble.

    I tried declaring the button with events in the module and added a handler,
    but it didn't trigger. I then made my own event in the form, raised in
    inside the button's click event and put a handler for that in the module.
    Again no good.

    Obviously I'm missing something. Can anyone help me do this?

    Art

  • Steven Nagy

    #2
    Re: Button event

    Post relevant code please

    Comment

    • Herfried K. Wagner [MVP]

      #3
      Re: Button event

      "Art" <Art@discussion s.microsoft.com > schrieb:[color=blue]
      > I've got a main module that instantiates a form and then does
      > form.showdialog .
      >
      > The form has a button. I want the main module to respond to a click event
      > from the button. I'm having trouble.
      >
      > I tried declaring the button with events in the module and added a
      > handler,
      > but it didn't trigger. I then made my own event in the form, raised in
      > inside the button's click event and put a handler for that in the module.
      > Again no good.[/color]

      Private WithEvents Button1 As Button
      ....
      Dim f As New Form1()
      Button1 = f.Button1
      f.Show()
      ....
      Private Sub Button1_Click( _
      ByVal sender As Object, ByVal e As EventArgs _
      ) Handles Button1.Click
      MsgBox("Hello world!")
      End Sub
      ///

      --
      M S Herfried K. Wagner
      M V P <URL:http://dotnet.mvps.org/>
      V B <URL:http://classicvb.org/petition/>

      Comment

      • Art

        #4
        Re: Button event

        Herfried,

        Thank you very much -- it worked very well. I think I got confused as to
        which object I needed to declare with events.

        Thanks again,

        Art

        "Herfried K. Wagner [MVP]" wrote:
        [color=blue]
        > "Art" <Art@discussion s.microsoft.com > schrieb:[color=green]
        > > I've got a main module that instantiates a form and then does
        > > form.showdialog .
        > >
        > > The form has a button. I want the main module to respond to a click event
        > > from the button. I'm having trouble.
        > >
        > > I tried declaring the button with events in the module and added a
        > > handler,
        > > but it didn't trigger. I then made my own event in the form, raised in
        > > inside the button's click event and put a handler for that in the module.
        > > Again no good.[/color]
        >
        > Private WithEvents Button1 As Button
        > ....
        > Dim f As New Form1()
        > Button1 = f.Button1
        > f.Show()
        > ....
        > Private Sub Button1_Click( _
        > ByVal sender As Object, ByVal e As EventArgs _
        > ) Handles Button1.Click
        > MsgBox("Hello world!")
        > End Sub
        > ///
        >
        > --
        > M S Herfried K. Wagner
        > M V P <URL:http://dotnet.mvps.org/>
        > V B <URL:http://classicvb.org/petition/>
        >
        >[/color]

        Comment

        Working...