473,706 Members | 1,988 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Determine the current event

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
Jul 21 '05 #1
18 2882
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# On**********@BT Internet.com
Jul 21 '05 #2
> 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# ]" <te************ *************** @BTOpenworld.co m>
wrote in message news:%2******** ********@TK2MSF TNGP11.phx.gbl. .. 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# On**********@BT Internet.com

Jul 21 '05 #3
"Christophe r W. Douglas" <ch************ ********@SPAM.s rs.com>
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

Jul 21 '05 #4
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# ]"
<te************ *************** @BTOpenworld.co m> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
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# On**********@BT Internet.com


Regards - OHM# On**********@BT Internet.com
Jul 21 '05 #5
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(By Val sender As Object, ByVal e As CancelEventArgs )
Handles MyBase.Closing

DoCommonStuff()
' Code for closing goes here

End Sub

Private Sub Form_VisibleCha nged(ByVal sender As Object, ByVal e As
EventArgs) Handles MyBase.VisibleC hanged

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.

"Christophe r W. Douglas" <ch************ ********@SPAM.s rs.com> wrote in
message news:%2******** **********@TK2M SFTNGP11.phx.gb l...
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

Jul 21 '05 #6
> what would be your answer to the OP

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

"One Handed Man [ OHM# ]" <te************ *************** @BTOpenworld.co m>
wrote in message news:ez******** ******@TK2MSFTN GP09.phx.gbl...
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# ]"
<te************ *************** @BTOpenworld.co m> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
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# On**********@BT Internet.com


Regards - OHM# On**********@BT Internet.com

Jul 21 '05 #7
> 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" <az*******@free net.de> wrote in message
news:uH******** ******@TK2MSFTN GP09.phx.gbl... "Christophe r W. Douglas" <ch************ ********@SPAM.s rs.com>
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

Jul 21 '05 #8
Cor
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
Jul 21 '05 #9
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# ]"
<te************ *************** @BTOpenworld.co m> wrote in message
news:ez******** ******@TK2MSFTN GP09.phx.gbl...
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# ]"
<te************ *************** @BTOpenworld.co m> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
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# On**********@BT Internet.com


Regards - OHM# On**********@BT Internet.com


Regards - OHM# On**********@BT Internet.com
Jul 21 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2217
by: Jordan | last post by:
I am dynamically inserting an html <input> tag as text (equivalent of an image button) into a page via a Literal control. Something like this gets inserted: <input type="image" name="MyImageButton" id="MyImageButton" src="somePic.jpg" /> I want for the code-behind to "know" when the user clicked on the image - but I don't want to also have to dynamically specify a delegate for an event procedure to handle this control which is really...
19
2087
by: Christopher W. Douglas | last post by:
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...
3
1847
by: jaYPee | last post by:
is there a way to know if the form is edited or not after calling addnew? Me.BindingContext(DsStudentCourse1, "Students").AddNew() because i got an error after closing the form. because in my form closing event i have a code to call the EndCurrentEdit to determine if the dataset has changes or not. here is my code in closing event Private Sub Students_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs)...
0
8783
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9287
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9157
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9056
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8999
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6615
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5939
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4710
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2503
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.