473,325 Members | 2,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

How can I use the object passed in the event

Hi,

I have a form which contains about 100 Textboxes but I mapped all their
onTextchanged event to the same procedure. Now I would like to know if it is
possible from the sender argument passed to the procedure to get to know
which of the 100 textboxes was changed.

My code is :
private void textBox1_TextChanged(object sender, System.EventArgs e)
{
//Here I need to get the name of which texbox was changed
}
private void button1_Click_1(object sender, System.EventArgs e)
{
int iCnt = 0;
for (iCnt=0;iCnt<=100;iCnt++)
{
TextBox iLabel = new TextBox();
iLabel.Parent = panel1;
iLabel.Text = iCnt.ToString();
iLabel.Top = (iCnt * 21);
iLabel.Name = ("Form" + iCnt.ToString());
iLabel.TextChanged += new
System.EventHandler(this.textBox1_TextChanged);
iLabel.Refresh();
}
}

Thanks
Ivan
Apr 19 '06 #1
2 1285
Ivan Sammut wrote:
I have a form which contains about 100 Textboxes but I mapped all their
onTextchanged event to the same procedure. Now I would like to know if it is
possible from the sender argument passed to the procedure to get to know
which of the 100 textboxes was changed.


Yes - that's the point of the sender argument. Just cast it to TextBox,
and it'll be the one which generated the event.

Jon

Apr 19 '06 #2
Hi Ivan,

The sender is a reference to the object that raised the event. In this case,
it is always going to be a TextBox. However, you can use the same Event
Handler for various different Controls in a Windows Form. All
System.Windows.Forms.Controls have a Name property. So, I would suggest
casting the sender as a Control to get the name (in case you ever use the
same Event Handler for a different Control):

string name = ((Control)sender).Name;

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

"Ivan Sammut" <sa*****@hotmail.com> wrote in message
news:ep**************@TK2MSFTNGP03.phx.gbl...
Hi,

I have a form which contains about 100 Textboxes but I mapped all their
onTextchanged event to the same procedure. Now I would like to know if it
is
possible from the sender argument passed to the procedure to get to know
which of the 100 textboxes was changed.

My code is :
private void textBox1_TextChanged(object sender, System.EventArgs e)
{
//Here I need to get the name of which texbox was changed
}
private void button1_Click_1(object sender, System.EventArgs e)
{
int iCnt = 0;
for (iCnt=0;iCnt<=100;iCnt++)
{
TextBox iLabel = new TextBox();
iLabel.Parent = panel1;
iLabel.Text = iCnt.ToString();
iLabel.Top = (iCnt * 21);
iLabel.Name = ("Form" + iCnt.ToString());
iLabel.TextChanged += new
System.EventHandler(this.textBox1_TextChanged);
iLabel.Refresh();
}
}

Thanks
Ivan

Apr 19 '06 #3

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

Similar topics

3
by: Christoph Boget | last post by:
Please forgive my ignorance as I'm still new to developing w/C# (and in windows in general). So if I use the wrong terms, please bear with me. I'm using VS.NET and defining the events have been...
17
by: Hazz | last post by:
In this sample code of ownerdraw drawmode, why does the '(ComboBox) sender' line of code need to be there in this event handler? Isn't cboFont passed via the managed heap, not the stack, into this...
3
by: Maurice Walmsley | last post by:
I'll avoid tell you how lame I am and get straight to the question... I need a good expanation to the "ByVal sender As Object, ByVal e As System.EventArgs" part of; Public Sub...
12
by: Jim Hammond | last post by:
I am passing the whole object instead or parameters in my select and update methods. I can get the updated object if I set UpdateMethod, let ASP.NET autogenerate an update button, and then press...
2
by: Martin Honnen | last post by:
I was playing around with canvas support in recent Safari, Mozilla and Opera (only version 9 preview) but run into issues with Safari related to the very old DOM Level 0 Image object for preloading...
5
by: Michael Moreno | last post by:
Hello, In a class I have this code: public object Obj; If Obj is a COM object I would like to call in the Dispose() method the following code: ...
16
by: anonymous.user0 | last post by:
The way I understand it, if I have an object Listener that has registered as a listener for some event Event that's produced by an object Emitter, as long as Emitter is still allocated Listener...
6
by: Jeremy | last post by:
I want each instance of an object to be able to listen for input events. When the event occurs, a method of the object should be called, such that "this" is in scope and refers to the object...
6
by: Murray Hopkins | last post by:
Hi. THE QUESTION: How do I get a reference to my Object when processing an event handler bound to an html element ? CONTEXT: Sorry if it is a bit long. I am developing a JS calendar tool....
1
tlhintoq
by: tlhintoq | last post by:
I'm pretty sure this is language independent and is going to be the same whether it's VC or C# - but my project is C# WIndows Forms just in case. Does anyone have a good handle on the sequence of...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.