PC Review


Reply
Thread Tools Rate Thread

Determine the current event

 
 
Christopher W. Douglas
Guest
Posts: n/a
 
      9th Dec 2003
I am writing a VB.NET application in Visual Studio 2003. I have written a
method that handles several events, such as closing a form and changing the
visible status of a form. I have some code that applies to all these
events, but I need to have specific code execute when the form closes. The
properties for this method are sender (the originator) and e (event
arguments). I know how to get typeof (sender) to determine what form or
control the event originated from, but how do I determine which event was
fired? I would think that eventargs contains the type of event that fired,
but I could not find anything in MSDN detailing this. Thanks for your help.

--
Christopher W. Douglas
SRS Technologies, Inc.
christopher (dot) douglas (at) srs (dot) com


 
Reply With Quote
 
 
 
 
One Handed Man [ OHM# ]
Guest
Posts: n/a
 
      9th Dec 2003
You need to getType of 'e' to determine what type it is and then take it
from there.

OHM#

Christopher W. Douglas wrote:
> I am writing a VB.NET application in Visual Studio 2003. I have
> written a method that handles several events, such as closing a form
> and changing the visible status of a form. I have some code that
> applies to all these events, but I need to have specific code execute
> when the form closes. The properties for this method are sender (the
> originator) and e (event arguments). I know how to get typeof
> (sender) to determine what form or control the event originated from,
> but how do I determine which event was fired? I would think that
> eventargs contains the type of event that fired, but I could not find
> anything in MSDN detailing this. Thanks for your help.


Regards - OHM# (E-Mail Removed)


 
Reply With Quote
 
Armin Zingler
Guest
Posts: n/a
 
      9th Dec 2003
"Christopher W. Douglas" <(E-Mail Removed)>
schrieb
> I am writing a VB.NET application in Visual Studio 2003. I have
> written a method that handles several events, such as closing a form
> and changing the visible status of a form. I have some code that
> applies to all these events, but I need to have specific code execute
> when the form closes. The properties for this method are sender (the
> originator) and e (event arguments). I know how to get typeof
> (sender) to determine what form or control the event originated from,
> but how do I determine which event was fired? I would think that
> eventargs contains the type of event that fired, but I could not find
> anything in MSDN detailing this. Thanks for your help.


If you want to handle different events you should write different
procedures. Otherwise it's like pouring two glasses of water together and
trying to find out where each drop came from.


--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

 
Reply With Quote
 
Codemonkey
Guest
Posts: n/a
 
      9th Dec 2003
> You need to getType of 'e' to determine what type it
> is and then take it from there.


GetType(e) will return the same thing each time (EventArgs class) because it
is the same method that is handling the different events mentioned.


"One Handed Man [ OHM# ]" <terry_burnsREMOVE%FOR%NO%(E-Mail Removed)>
wrote in message news:%(E-Mail Removed)...
> You need to getType of 'e' to determine what type it is and then take it
> from there.
>
> OHM#
>
> Christopher W. Douglas wrote:
> > I am writing a VB.NET application in Visual Studio 2003. I have
> > written a method that handles several events, such as closing a form
> > and changing the visible status of a form. I have some code that
> > applies to all these events, but I need to have specific code execute
> > when the form closes. The properties for this method are sender (the
> > originator) and e (event arguments). I know how to get typeof
> > (sender) to determine what form or control the event originated from,
> > but how do I determine which event was fired? I would think that
> > eventargs contains the type of event that fired, but I could not find
> > anything in MSDN detailing this. Thanks for your help.

>
> Regards - OHM# (E-Mail Removed)
>
>



 
Reply With Quote
 
One Handed Man [ OHM# ]
Guest
Posts: n/a
 
      9th Dec 2003
Thinking about it, yes your right! , what would be your answer to the OP
then?

OHM

Codemonkey wrote:
>> You need to getType of 'e' to determine what type it
>> is and then take it from there.

>
> GetType(e) will return the same thing each time (EventArgs class)
> because it is the same method that is handling the different events
> mentioned.
>
>
> "One Handed Man [ OHM# ]"
> <terry_burnsREMOVE%FOR%NO%(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
>> You need to getType of 'e' to determine what type it is and then
>> take it from there.
>>
>> OHM#
>>
>> Christopher W. Douglas wrote:
>>> I am writing a VB.NET application in Visual Studio 2003. I have
>>> written a method that handles several events, such as closing a form
>>> and changing the visible status of a form. I have some code that
>>> applies to all these events, but I need to have specific code
>>> execute when the form closes. The properties for this method are
>>> sender (the originator) and e (event arguments). I know how to get
>>> typeof (sender) to determine what form or control the event
>>> originated from, but how do I determine which event was fired? I
>>> would think that eventargs contains the type of event that fired,
>>> but I could not find anything in MSDN detailing this. Thanks for
>>> your help.

>>
>> Regards - OHM# (E-Mail Removed)


Regards - OHM# (E-Mail Removed)


 
Reply With Quote
 
Codemonkey
Guest
Posts: n/a
 
      9th Dec 2003
Christopher,

You are correct that the "Sender" argument identifies the form or control
that raised the event. The "e" or EventArgs argument is simply an object
that contains additional arguments specific to that event. As many different
events share the same type of parameters (called its "Signature") you cannot
identifty the actual event being rased from this parameter.

You would be better off having separate event handler methods for each event
and moving the common code into a separate procedure which is called from
each event handler.


For example:
---------------------------------
Private Sub Form_Closing(ByVal sender As Object, ByVal e As CancelEventArgs)
Handles MyBase.Closing

DoCommonStuff()
' Code for closing goes here

End Sub

Private Sub Form_VisibleChanged(ByVal sender As Object, ByVal e As
EventArgs) Handles MyBase.VisibleChanged

DoCommonStuff()
' Code for visible changed goes here

End Sub

Private Sub DoCommonStuff()

' Do stuff common to both events here

End Sub
--------------------------------------------

Hope this helps,

Trev.

"Christopher W. Douglas" <(E-Mail Removed)> wrote in
message news:%23r%(E-Mail Removed)...
> I am writing a VB.NET application in Visual Studio 2003. I have written a
> method that handles several events, such as closing a form and changing

the
> visible status of a form. I have some code that applies to all these
> events, but I need to have specific code execute when the form closes. The
> properties for this method are sender (the originator) and e (event
> arguments). I know how to get typeof (sender) to determine what form or
> control the event originated from, but how do I determine which event was
> fired? I would think that eventargs contains the type of event that

fired,
> but I could not find anything in MSDN detailing this. Thanks for your

help.
>
> --
> Christopher W. Douglas
> SRS Technologies, Inc.
> christopher (dot) douglas (at) srs (dot) com
>
>



 
Reply With Quote
 
Codemonkey
Guest
Posts: n/a
 
      9th Dec 2003
> what would be your answer to the OP

My post hasn't seemed to appear yet. Watch this space

"One Handed Man [ OHM# ]" <terry_burnsREMOVE%FOR%NO%(E-Mail Removed)>
wrote in message news:ez1a$(E-Mail Removed)...
> Thinking about it, yes your right! , what would be your answer to the OP
> then?
>
> OHM
>
> Codemonkey wrote:
> >> You need to getType of 'e' to determine what type it
> >> is and then take it from there.

> >
> > GetType(e) will return the same thing each time (EventArgs class)
> > because it is the same method that is handling the different events
> > mentioned.
> >
> >
> > "One Handed Man [ OHM# ]"
> > <terry_burnsREMOVE%FOR%NO%(E-Mail Removed)> wrote in message
> > news:%(E-Mail Removed)...
> >> You need to getType of 'e' to determine what type it is and then
> >> take it from there.
> >>
> >> OHM#
> >>
> >> Christopher W. Douglas wrote:
> >>> I am writing a VB.NET application in Visual Studio 2003. I have
> >>> written a method that handles several events, such as closing a form
> >>> and changing the visible status of a form. I have some code that
> >>> applies to all these events, but I need to have specific code
> >>> execute when the form closes. The properties for this method are
> >>> sender (the originator) and e (event arguments). I know how to get
> >>> typeof (sender) to determine what form or control the event
> >>> originated from, but how do I determine which event was fired? I
> >>> would think that eventargs contains the type of event that fired,
> >>> but I could not find anything in MSDN detailing this. Thanks for
> >>> your help.
> >>
> >> Regards - OHM# (E-Mail Removed)

>
> Regards - OHM# (E-Mail Removed)
>
>



 
Reply With Quote
 
Codemonkey
Guest
Posts: n/a
 
      9th Dec 2003
> Otherwise it's like pouring two glasses of water together and
> trying to find out where each drop came from.


lol. I like the metaphor. Very apt.


"Armin Zingler" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "Christopher W. Douglas" <(E-Mail Removed)>
> schrieb
> > I am writing a VB.NET application in Visual Studio 2003. I have
> > written a method that handles several events, such as closing a form
> > and changing the visible status of a form. I have some code that
> > applies to all these events, but I need to have specific code execute
> > when the form closes. The properties for this method are sender (the
> > originator) and e (event arguments). I know how to get typeof
> > (sender) to determine what form or control the event originated from,
> > but how do I determine which event was fired? I would think that
> > eventargs contains the type of event that fired, but I could not find
> > anything in MSDN detailing this. Thanks for your help.

>
> If you want to handle different events you should write different
> procedures. Otherwise it's like pouring two glasses of water together and
> trying to find out where each drop came from.
>
>
> --
> Armin
>
> http://www.plig.net/nnq/nquote.html
> http://www.netmeister.org/news/learn2quote.html
>



 
Reply With Quote
 
Cor
Guest
Posts: n/a
 
      9th Dec 2003
Hi Armin,

> If you want to handle different events you should write different
> procedures. Otherwise it's like pouring two glasses of water together and
> trying to find out where each drop came from.


That is a very good answer.

Describes exactly the problem in my opinion..

(And I am serious before you don't believe it.)

Cor


 
Reply With Quote
 
One Handed Man [ OHM# ]
Guest
Posts: n/a
 
      9th Dec 2003
Good advice CM, I really should have thought more before my posting <slaps
self on head>

Thanks !

OHM

Codemonkey wrote:
>> what would be your answer to the OP

>
> My post hasn't seemed to appear yet. Watch this space
>
> "One Handed Man [ OHM# ]"
> <terry_burnsREMOVE%FOR%NO%(E-Mail Removed)> wrote in message
> news:ez1a$(E-Mail Removed)...
>> Thinking about it, yes your right! , what would be your answer to
>> the OP then?
>>
>> OHM
>>
>> Codemonkey wrote:
>>>> You need to getType of 'e' to determine what type it
>>>> is and then take it from there.
>>>
>>> GetType(e) will return the same thing each time (EventArgs class)
>>> because it is the same method that is handling the different events
>>> mentioned.
>>>
>>>
>>> "One Handed Man [ OHM# ]"
>>> <terry_burnsREMOVE%FOR%NO%(E-Mail Removed)> wrote in message
>>> news:%(E-Mail Removed)...
>>>> You need to getType of 'e' to determine what type it is and then
>>>> take it from there.
>>>>
>>>> OHM#
>>>>
>>>> Christopher W. Douglas wrote:
>>>>> I am writing a VB.NET application in Visual Studio 2003. I have
>>>>> written a method that handles several events, such as closing a
>>>>> form and changing the visible status of a form. I have some code
>>>>> that applies to all these events, but I need to have specific code
>>>>> execute when the form closes. The properties for this method are
>>>>> sender (the originator) and e (event arguments). I know how to
>>>>> get typeof (sender) to determine what form or control the event
>>>>> originated from, but how do I determine which event was fired? I
>>>>> would think that eventargs contains the type of event that fired,
>>>>> but I could not find anything in MSDN detailing this. Thanks for
>>>>> your help.
>>>>
>>>> Regards - OHM# (E-Mail Removed)

>>
>> Regards - OHM# (E-Mail Removed)


Regards - OHM# (E-Mail Removed)


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Determine current namespace vooose Microsoft C# .NET 3 8th Feb 2005 09:43 AM
How to determine the current thread Howard Weiss Microsoft VC .NET 1 21st Jul 2004 03:40 AM
Determine Current Selection Gary Microsoft Excel Programming 3 29th Mar 2004 10:28 AM
Determine the current event Christopher W. Douglas Microsoft Dot NET 18 9th Dec 2003 05:38 PM
Determine current sub Chuck Microsoft Dot NET Framework 4 27th Nov 2003 03:08 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:45 PM.