Inserting an event handler 
Author Message
 Inserting an event handler

It seems to me this should be obvious, but I can't find the answer.

When I want to insert code for handling a certain event, I think it should
be possible to click on something that inserts the skeleton into the code.
This happens for the default event when you double click a control in the
designer.

Is there a feature that does this?

--
Bill McCarthy



Mon, 07 Feb 2005 06:20:54 GMT  
 Inserting an event handler
What I'm after is being able to do it while in design mode or while looking
at the code.
AddHandler doesn't quite do it.

--
Bill McCarthy

Quote:

> You could use addhandler...But as far as skeleton code, sorry, none that
> I am aware of, use addhandler

> Cade


> > It seems to me this should be obvious, but I can't find the answer.

> > When I want to insert code for handling a certain event, I think it
should
> > be possible to click on something that inserts the skeleton into the
code.
> > This happens for the default event when you double click a control in
the
> > designer.

> > Is there a feature that does this?

> > --
> > Bill McCarthy




Mon, 07 Feb 2005 07:54:16 GMT  
 Inserting an event handler
If you declare a class level object withevents, it will show up in the
object browser at the top of the window, and you can use that to get the
proper signature for the events.

It's an ugly hack, but it works.

--
Toby Herring
Software Architects, Inc.
MCDBA, MCSD



Quote:
> What I'm after is being able to do it while in design mode or while
looking
> at the code.
> AddHandler doesn't quite do it.

> --
> Bill McCarthy




Quote:
> > You could use addhandler...But as far as skeleton code, sorry, none that
> > I am aware of, use addhandler

> > Cade


> > > It seems to me this should be obvious, but I can't find the answer.

> > > When I want to insert code for handling a certain event, I think it
> should
> > > be possible to click on something that inserts the skeleton into the
> code.
> > > This happens for the default event when you double click a control in
> the
> > > designer.

> > > Is there a feature that does this?

> > > --
> > > Bill McCarthy




Mon, 07 Feb 2005 08:01:09 GMT  
 Inserting an event handler
This is the way to do it though I don't know that I would characterize it as
a hack; that is the way the feature was designed.  So to step you through it
let's say I have:

class foo
    event SomeEvent( x as integer )
end class

module Main
    WithEvents x as foo
    '<--say the cursor is here
end module

In the left dropdown at the top of the coding pane, you will find an entry
for 'x' - the WithEvents variable.  If you select that, the declarations
dropdown (the one just to the right of the dropdown in which you selected
'x') will have an entry for SomeEvent (it has a lightening bolt next to it
indicating it is an event).  If you select it, the IDE will insert a handler
for you using the default name: sub <withEvent variable>_<Event Name>(
<event signature> )

Tyler
Vb.NET Development
--
This posting is provided "AS IS" with no warranties, and confers no rights.


Quote:
> If you declare a class level object withevents, it will show up in the
> object browser at the top of the window, and you can use that to get the
> proper signature for the events.

> It's an ugly hack, but it works.

> --
> Toby Herring
> Software Architects, Inc.
> MCDBA, MCSD



> > What I'm after is being able to do it while in design mode or while
> looking
> > at the code.
> > AddHandler doesn't quite do it.

> > --
> > Bill McCarthy



> > > You could use addhandler...But as far as skeleton code, sorry, none
that
> > > I am aware of, use addhandler

> > > Cade


> > > > It seems to me this should be obvious, but I can't find the answer.

> > > > When I want to insert code for handling a certain event, I think it
> > should
> > > > be possible to click on something that inserts the skeleton into the
> > code.
> > > > This happens for the default event when you double click a control
in
> > the
> > > > designer.

> > > > Is there a feature that does this?

> > > > --
> > > > Bill McCarthy




Tue, 08 Feb 2005 04:44:20 GMT  
 Inserting an event handler
It's a hack if you don't want/need a class-level declaration and you're only
declaring the WithEvents variable to get the delegate signatures.

My suggestion was to temporarily add a never-used variable withevents, then
delete the declaration after you get the delegates.

--
Toby Herring
Software Architects, Inc.
MCDBA, MCSD



Quote:
> This is the way to do it though I don't know that I would characterize it
as
> a hack; that is the way the feature was designed.  So to step you through
it
> let's say I have:

> class foo
>     event SomeEvent( x as integer )
> end class

> module Main
>     WithEvents x as foo
>     '<--say the cursor is here
> end module

> In the left dropdown at the top of the coding pane, you will find an entry
> for 'x' - the WithEvents variable.  If you select that, the declarations
> dropdown (the one just to the right of the dropdown in which you selected
> 'x') will have an entry for SomeEvent (it has a lightening bolt next to it
> indicating it is an event).  If you select it, the IDE will insert a
handler
> for you using the default name: sub <withEvent variable>_<Event Name>(
> <event signature> )

> Tyler
> Vb.NET Development
> --
> This posting is provided "AS IS" with no warranties, and confers no
rights.



> > If you declare a class level object withevents, it will show up in the
> > object browser at the top of the window, and you can use that to get the
> > proper signature for the events.

> > It's an ugly hack, but it works.

> > --
> > Toby Herring
> > Software Architects, Inc.
> > MCDBA, MCSD



> > > What I'm after is being able to do it while in design mode or while
> > looking
> > > at the code.
> > > AddHandler doesn't quite do it.

> > > --
> > > Bill McCarthy



> > > > You could use addhandler...But as far as skeleton code, sorry, none
> that
> > > > I am aware of, use addhandler

> > > > Cade


> > > > > It seems to me this should be obvious, but I can't find the
answer.

> > > > > When I want to insert code for handling a certain event, I think
it
> > > should
> > > > > be possible to click on something that inserts the skeleton into
the
> > > code.
> > > > > This happens for the default event when you double click a control
> in
> > > the
> > > > > designer.

> > > > > Is there a feature that does this?



Tue, 08 Feb 2005 05:31:36 GMT  
 Inserting an event handler

Quote:
> This is the way to do it though I don't know that I would
> characterize it as a hack; that is the way the feature was
> designed.  

If you need withEvents to be able to use AddHandler, it is a hack.

Armin



Tue, 08 Feb 2005 06:39:32 GMT  
 Inserting an event handler
Yes, if you are going to use AddHandler then this is unfortunate and the
point that we could do something to make using AddHandler() easier to use is
well taken and I will pass that feedback on.  Part of the confusion is that
I was responding directly to: "When I want to insert code for handling a
certain event, I think it should be possible to click on something that
inserts the skeleton into the code".  I read the question more broadly
(without taking into account the AddHandler spin) because I didn't think the
original question was about how to do this with AddHandler.  I percieve
AddHandler as a false constraint on the question as it had been introduced
into the thread as a possible solution but was subsequently discarded.  I
think the most direct route to getting to a place where: "When I want to
insert code for handling a certain event, I think it should be possible to
click on something that inserts the skeleton into the code" is to illustrate
how this can be done using WithEvents and the dropdowns.  I think what
emerged about AddHandler() being difficult to use because you have to come
up with the delegate signatures is a good point which I'll forward to the
team.

Tyler
VB.NET Development
--
This posting is provided "AS IS" with no warranties, and confers no rights.


Quote:
> It's a hack if you don't want/need a class-level declaration and you're
only
> declaring the WithEvents variable to get the delegate signatures.

> My suggestion was to temporarily add a never-used variable withevents,
then
> delete the declaration after you get the delegates.

> --
> Toby Herring
> Software Architects, Inc.
> MCDBA, MCSD



> > This is the way to do it though I don't know that I would characterize
it
> as
> > a hack; that is the way the feature was designed.  So to step you
through
> it
> > let's say I have:

> > class foo
> >     event SomeEvent( x as integer )
> > end class

> > module Main
> >     WithEvents x as foo
> >     '<--say the cursor is here
> > end module

> > In the left dropdown at the top of the coding pane, you will find an
entry
> > for 'x' - the WithEvents variable.  If you select that, the declarations
> > dropdown (the one just to the right of the dropdown in which you
selected
> > 'x') will have an entry for SomeEvent (it has a lightening bolt next to
it
> > indicating it is an event).  If you select it, the IDE will insert a
> handler
> > for you using the default name: sub <withEvent variable>_<Event Name>(
> > <event signature> )

> > Tyler
> > Vb.NET Development
> > --
> > This posting is provided "AS IS" with no warranties, and confers no
> rights.



> > > If you declare a class level object withevents, it will show up in the
> > > object browser at the top of the window, and you can use that to get
the
> > > proper signature for the events.

> > > It's an ugly hack, but it works.

> > > --
> > > Toby Herring
> > > Software Architects, Inc.
> > > MCDBA, MCSD



> > > > What I'm after is being able to do it while in design mode or while
> > > looking
> > > > at the code.
> > > > AddHandler doesn't quite do it.

> > > > --
> > > > Bill McCarthy



> > > > > You could use addhandler...But as far as skeleton code, sorry,
none
> > that
> > > > > I am aware of, use addhandler

> > > > > Cade


> > > > > > It seems to me this should be obvious, but I can't find the
> answer.

> > > > > > When I want to insert code for handling a certain event, I think
> it
> > > > should
> > > > > > be possible to click on something that inserts the skeleton into
> the
> > > > code.
> > > > > > This happens for the default event when you double click a
control
> > in
> > > > the
> > > > > > designer.

> > > > > > Is there a feature that does this?



Wed, 09 Feb 2005 04:35:07 GMT  
 Inserting an event handler
Sorry, you are correct.  I did make an assumption based on my own
programming style.

I tend to declare all data at the smallest reasonable scope, therefore
class-level objects are rare in my code.  (Unless, of course, it's some sort
of data class, and the object in question is actually used for data
persistence.)

Anywho, with my coding style, I do run into this AddHandler issue
frequently.  I've actually found that the process of looking up delegate
signatures is quite time-consuming (from a project perspective) and it would
be nice to have a better way to do it.  So far, the most effective and
accurate method I've found is to use WithEvents as described.

--
Toby Herring
Software Architects, Inc.
MCDBA, MCSD



Quote:
> Yes, if you are going to use AddHandler then this is unfortunate and the
> point that we could do something to make using AddHandler() easier to use
is
> well taken and I will pass that feedback on.  Part of the confusion is
that
> I was responding directly to: "When I want to insert code for handling a
> certain event, I think it should be possible to click on something that
> inserts the skeleton into the code".  I read the question more broadly
> (without taking into account the AddHandler spin) because I didn't think
the
> original question was about how to do this with AddHandler.  I percieve
> AddHandler as a false constraint on the question as it had been introduced
> into the thread as a possible solution but was subsequently discarded.  I
> think the most direct route to getting to a place where: "When I want to
> insert code for handling a certain event, I think it should be possible to
> click on something that inserts the skeleton into the code" is to
illustrate
> how this can be done using WithEvents and the dropdowns.  I think what
> emerged about AddHandler() being difficult to use because you have to come
> up with the delegate signatures is a good point which I'll forward to the
> team.

> Tyler
> VB.NET Development
> --
> This posting is provided "AS IS" with no warranties, and confers no
rights.



> > It's a hack if you don't want/need a class-level declaration and you're
> only
> > declaring the WithEvents variable to get the delegate signatures.

> > My suggestion was to temporarily add a never-used variable withevents,
> then
> > delete the declaration after you get the delegates.

> > --
> > Toby Herring
> > Software Architects, Inc.
> > MCDBA, MCSD



> > > This is the way to do it though I don't know that I would characterize
> it
> > as
> > > a hack; that is the way the feature was designed.  So to step you
> through
> > it
> > > let's say I have:

> > > class foo
> > >     event SomeEvent( x as integer )
> > > end class

> > > module Main
> > >     WithEvents x as foo
> > >     '<--say the cursor is here
> > > end module

> > > In the left dropdown at the top of the coding pane, you will find an
> entry
> > > for 'x' - the WithEvents variable.  If you select that, the
declarations
> > > dropdown (the one just to the right of the dropdown in which you
> selected
> > > 'x') will have an entry for SomeEvent (it has a lightening bolt next
to
> it
> > > indicating it is an event).  If you select it, the IDE will insert a
> > handler
> > > for you using the default name: sub <withEvent variable>_<Event Name>(
> > > <event signature> )

> > > Tyler
> > > Vb.NET Development
> > > --
> > > This posting is provided "AS IS" with no warranties, and confers no
> > rights.



> > > > If you declare a class level object withevents, it will show up in
the
> > > > object browser at the top of the window, and you can use that to get
> the
> > > > proper signature for the events.

> > > > It's an ugly hack, but it works.

> > > > --
> > > > Toby Herring
> > > > Software Architects, Inc.
> > > > MCDBA, MCSD



> > > > > What I'm after is being able to do it while in design mode or
while
> > > > looking
> > > > > at the code.
> > > > > AddHandler doesn't quite do it.

> > > > > --
> > > > > Bill McCarthy



> > > > > > You could use addhandler...But as far as skeleton code, sorry,
> none
> > > that
> > > > > > I am aware of, use addhandler

> > > > > > Cade


> > > > > > > It seems to me this should be obvious, but I can't find the
> > answer.

> > > > > > > When I want to insert code for handling a certain event, I
think
> > it
> > > > > should
> > > > > > > be possible to click on something that inserts the skeleton
into
> > the
> > > > > code.
> > > > > > > This happens for the default event when you double click a
> control
> > > in
> > > > > the
> > > > > > > designer.

> > > > > > > Is there a feature that does this?



Mon, 14 Feb 2005 21:59:55 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. object created in workbook_open event handler disappears on exit from the event handler

2. Insert new Event and handler in a class !

3. handling multiple events with one event handler

4. handling multiple events with a single event handler

5. event handler for preview messages

6. is it possible to make other Event Handlers?

7. How to add an event handler to double click on a mail

8. Event handlers for controls added at run time

9. Outlook 2000: How to add an event handler to double click on a mail

10. Multiple Item Event Handler problems!

11. Multithreading in Com Add in blocks Outlook Event Handlers

12. Why would Application_Startup() event handler be ignored?

 

 
Powered by phpBB® Forum Software