Home All Groups Group Topic Archive Search About
Author
21 Jun 2006 2:15 AM
Art
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

Author
21 Jun 2006 2:37 AM
Steven Nagy
Post relevant code please
Author
21 Jun 2006 1:23 PM
Herfried K. Wagner [MVP]
"Art" <A**@discussions.microsoft.com> schrieb:
> 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.

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/>
Author
21 Jun 2006 6:23 PM
Art
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

Show quoteHide quote
"Herfried K. Wagner [MVP]" wrote:

> "Art" <A**@discussions.microsoft.com> schrieb:
> > 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.
>
> 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/>
>
>