R
Rich P
My actual problem is in casting the sender object
In VB.Net I can handle control events for multiple controls like this:
-------------------------------------------
Dim cnt() As Control
cnt = New Control(){btn1, btn2, combo1, combo2}
For Each ct As Control in cnt
AddHandler ct.Click, AddressOf ClickIt()
Next
Private Sub ClickIt(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Dim str1 As String = CType(sender, Control).Name
Console.WriteLine(str1)
End Sub
--------------------------------------------
I believe in C# I can do this
Control cnt[] = New Control(){btn1, btn2, combo1, combo2};
foreach Control cn In cnt
AddHandler cn.Click, AddressOf ClickIt();
next
private void ClickIt(object sender, EventArgs e)
{
String str1 = ? // how to cast sender?
}
Is this the correct way to add event handlers in C#? How to cast the
sender object?
Thanks,
Rich
In VB.Net I can handle control events for multiple controls like this:
-------------------------------------------
Dim cnt() As Control
cnt = New Control(){btn1, btn2, combo1, combo2}
For Each ct As Control in cnt
AddHandler ct.Click, AddressOf ClickIt()
Next
Private Sub ClickIt(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Dim str1 As String = CType(sender, Control).Name
Console.WriteLine(str1)
End Sub
--------------------------------------------
I believe in C# I can do this
Control cnt[] = New Control(){btn1, btn2, combo1, combo2};
foreach Control cn In cnt
AddHandler cn.Click, AddressOf ClickIt();
next
private void ClickIt(object sender, EventArgs e)
{
String str1 = ? // how to cast sender?
}
Is this the correct way to add event handlers in C#? How to cast the
sender object?
Thanks,
Rich