473,795 Members | 2,865 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do you determine which event called another event?

Hi there

I have a form with two TextBoxes each of which has an _Enter event.
In each case the _Enter event binds to the same Excel
SheetSelectionC hange event.

What I want to know is: within the SheetSelectionC hange event how can
I determine which _Enter event fired it and therefore which TextBox I
should be manipulating by this code?

I have tried working off the Focused property of the TextBox but
unfortunately as you shift to Excel this changes.

Thanks for your advice
Sep 5 '08 #1
8 1891
On Fri, 05 Sep 2008 08:39:52 -0700, pinkfloydfan
<ll************ *@googlemail.co mwrote:
I have a form with two TextBoxes each of which has an _Enter event.
In each case the _Enter event binds to the same Excel
SheetSelectionC hange event. [...]
The TextBox class has no "_Enter" event, but it does inherit an "Enter"
event from the Control class. Is that what you mean?

Events cannot be "bound" from one to the other. So what do you really
mean when you write "binds to the same...event"?

You may want to consider posting an actual code sample. Working C# code
provides a much more reliable way to describe your working C# code.
Without understanding what your code is actually doing, there's no
reliable way to answer your question. And so far, you haven't described
your code in a way that makes sense. :(

Pete
Sep 5 '08 #2
If I understand you, you can check the ActiveControl or use the sender to
the event.

TextBox tb = Sender as TextBox;
if (tb != null)
MessageBox.show (tb.Name);
"pinkfloydf an" <ll************ *@googlemail.co mwrote in message
news:72******** *************** ***********@f63 g2000hsf.google groups.com...
Hi there

I have a form with two TextBoxes each of which has an _Enter event.
In each case the _Enter event binds to the same Excel
SheetSelectionC hange event.

What I want to know is: within the SheetSelectionC hange event how can
I determine which _Enter event fired it and therefore which TextBox I
should be manipulating by this code?

I have tried working off the Focused property of the TextBox but
unfortunately as you shift to Excel this changes.

Thanks for your advice

Sep 5 '08 #3
Hi Pete

Sorry for not being clear previously, I don't have the code to hand
just now but basically I have an event (a change in the range selected
on an Excel worksheet) that is trapped by the Enter event of two
separate TextBoxes.

What I want to know is how to determine which of the two Enter events
calls the Excel event.

Does that make it clearer?
Sep 5 '08 #4
On Fri, 05 Sep 2008 16:04:28 -0700, pinkfloydfan
<ll************ *@googlemail.co mwrote:
Hi Pete

Sorry for not being clear previously, I don't have the code to hand
just now but basically I have an event (a change in the range selected
on an Excel worksheet) that is trapped by the Enter event of two
separate TextBoxes.

What I want to know is how to determine which of the two Enter events
calls the Excel event.

Does that make it clearer?
Sorry, no. In fact, the above has practically the same contradictions
that your first post had.

What does it mean for an event to be "trapped" by another event? That's
definitely not C# jargon. What do you actually mean?

Again, I think it would be best if you'd just post the code. I don't have
a fundamental objection to people making up their own jargon, but that
doesn't mean I'm going to spend a lot of time trying to figure it out.
:) If you want to use terminology that has no specific meaning in the
context of C#, you'll have to include code so that we can actually
understand it.

Pete
Sep 5 '08 #5
On 06/09/2008 in message
<fe************ *************** *******@8g2000h se.googlegroups .com>
pinkfloydfan wrote:
>Hi Pete

Sorry for not being clear previously, I don't have the code to hand
just now but basically I have an event (a change in the range selected
on an Excel worksheet) that is trapped by the Enter event of two
separate TextBoxes.

What I want to know is how to determine which of the two Enter events
calls the Excel event.

Does that make it clearer?
I think you are trapping the Enter event of the Text Box, e.g.:

private void txtPath1_Enter( object sender, EventArgs e)
{
}

If you use the same event for both Text Boxes then you can work out which
one called it:
TextBox txtCaller = sender as TextBox.

If you have a separate event for each Text Box then you know which one was
entered.

If you want to use that information eleswhere then you could save it in a
module wide variable.

--
Jeff Gaines Damerham Hampshire UK
Tell me what you need, and I'll tell you how to get along without it.
Sep 5 '08 #6

"pinkfloydf an" <ll************ *@googlemail.co mwrote in message
news:72******** *************** ***********@f63 g2000hsf.google groups.com...
Hi there

I have a form with two TextBoxes each of which has an _Enter event.
In each case the _Enter event binds to the same Excel
SheetSelectionC hange event.

What I want to know is: within the SheetSelectionC hange event how can
I determine which _Enter event fired it and therefore which TextBox I
should be manipulating by this code?
To determine which control raised the event that caused the invocation of
your event handler, you can use the "sender" argument of the event handler -
it will be that control.
Sep 6 '08 #7
Thankyou all for your suggestions.

Unfortunately, the SheetSelectionC hange event does not have a sender
argument but I adapted the alternative solution suggested by Jeff and
have a string variable in the Form that is set by each TextBox's Enter
event and records the name of the TextBox when the event fires.

Have a good weekend
Sep 6 '08 #8
The Sender object in the parameters of an event handler contain the object
that raises the event.

You can determine which of the textboxes sent the message by just comparing
with, say textBox1. (Cast the Sender to a TextBox first)

You can also use other schemes such as using the Tag member of the TextBox
to contain some useful information or if you want to be really clever,
create a custom attribute and use it on your textbox.

--
--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
"pinkfloydf an" <ll************ *@googlemail.co mwrote in message
news:72******** *************** ***********@f63 g2000hsf.google groups.com...
Hi there

I have a form with two TextBoxes each of which has an _Enter event.
In each case the _Enter event binds to the same Excel
SheetSelectionC hange event.

What I want to know is: within the SheetSelectionC hange event how can
I determine which _Enter event fired it and therefore which TextBox I
should be manipulating by this code?

I have tried working off the Focused property of the TextBox but
unfortunately as you shift to Excel this changes.

Thanks for your advice
Sep 6 '08 #9

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

Similar topics

18
2889
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...
2
3342
by: Kian Goh | last post by:
Hi there, Just wonder what factor actually determine a session to end? What happen a user close the browser or switch to other website? Does the session end immediately or 20 minutes later? (20 minutes defined in Web.config) Thanks, Kian
3
1698
by: Denise | last post by:
I want to fire code when the user changes the value of a textbox. I only want it to fire when the user is finished eding the TextBox and leaves (not after each keystroke). I am using the Validating event (the Leave even seems similar), but this is called even when the user does not make a change. Is there a simple way to handle this other than manually setting boolean flags for each keystroke? I also find that the Validating event is begin...
3
1972
by: Dean Slindee | last post by:
I have a exception handling class that could be called from either a windows project app or a console project app. Is there any way for this class to determine which type of app called it without sending an window/console parameter from either app? Thanks, Dean Slindee
0
9672
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...
1
10163
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
10000
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...
0
9040
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7538
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
6780
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
5436
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.