473,587 Members | 2,324 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_TextCh anged(object sender, System.EventArg s e)
{
//Here I need to get the name of which texbox was changed
}
private void button1_Click_1 (object sender, System.EventArg s e)
{
int iCnt = 0;
for (iCnt=0;iCnt<=1 00;iCnt++)
{
TextBox iLabel = new TextBox();
iLabel.Parent = panel1;
iLabel.Text = iCnt.ToString() ;
iLabel.Top = (iCnt * 21);
iLabel.Name = ("Form" + iCnt.ToString() );
iLabel.TextChan ged += new
System.EventHan dler(this.textB ox1_TextChanged );
iLabel.Refresh( );
}
}

Thanks
Ivan
Apr 19 '06 #1
2 1300
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)sende r).Name;

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

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

"Ivan Sammut" <sa*****@hotmai l.com> wrote in message
news:ep******** ******@TK2MSFTN GP03.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_TextCh anged(object sender, System.EventArg s e)
{
//Here I need to get the name of which texbox was changed
}
private void button1_Click_1 (object sender, System.EventArg s e)
{
int iCnt = 0;
for (iCnt=0;iCnt<=1 00;iCnt++)
{
TextBox iLabel = new TextBox();
iLabel.Parent = panel1;
iLabel.Text = iCnt.ToString() ;
iLabel.Top = (iCnt * 21);
iLabel.Name = ("Form" + iCnt.ToString() );
iLabel.TextChan ged += new
System.EventHan dler(this.textB ox1_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
15237
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 really simple. Just double-click on the event and the definition for that event (along with the method) gets written. I see that the first...
17
2668
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 cboFont_DrawItem event handler? Why does it need to be cast? -hazz ,................. cboFont.Items.AddRange(FontFamily.Families); } private...
3
1895
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 button01_click(ByVal sender As Object, ByVal e As System.EventArgs) I dont understand any of that part. ByVal? sender? e? System.EventArgs? Do you know of any good...
12
8684
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 update after making changes, but I don't want that update button. How can I get the updated object when the user presses one of my other action...
2
6441
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 images. When doing e.g. var img = new Image(); img.onload = function (evt) { alert(this); }; img.src = 'whatever.gif';
5
2509
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: System.Runtime.InteropServices.Marshal.ReleaseComObject(Obj);
16
2884
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 will stay alive. Is this correct? If this is correct, I've got a problem. Let's say I've got an object Customer that has an PurchaseList...
6
6853
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 instance. Is this possible? Example: function MyConstructor(element) {
6
1805
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. One of the requirements is that the calendar will need to display a varying number of months (1..3)
1
1945
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 events when an event is raised and multiple classes are all subscribed to the event? Does each class get a copy of the argument? Does each...
0
7843
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8340
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...
1
7967
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...
0
8220
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...
1
5713
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...
0
3840
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...
0
3875
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2353
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1452
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.