D
David Anton
Using 'WithEvents' in VB, the event handlers for an object remain intact
after a re-assignment (see the following), but I can't find a convenient way
to do this in C#:
Public Class Form1
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents test As System.Windows.Forms.Button
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
test = Button1
End Sub
Private Sub button_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles test.Click
MsgBox(CType(sender, Button).Name)
If test Is Button1 Then
'Button2 will now react to all the events defined for 'test':
test = Button2
Else
'Button1 will now react to all the events defined for 'test':
test = Button1
End If
End Sub
End Class
I know that I can hard-code the event wireups in C#:
test.Click -= button_Click;
test = Button2;
test.Click += button_Click;
but obviously this becomes unworkable when you know that more event handlers
than just 'Click' are involved.
--
http://www.tangiblesoftwaresolutions.com
C++ to C#
C++ to VB
C++ to Java
Instant C#: VB to C#
Instant VB: C# to VB
Instant C++: VB or C# to C++/CLI
Java to VB & C# Converter: Java to VB or C#
after a re-assignment (see the following), but I can't find a convenient way
to do this in C#:
Public Class Form1
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents test As System.Windows.Forms.Button
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
test = Button1
End Sub
Private Sub button_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles test.Click
MsgBox(CType(sender, Button).Name)
If test Is Button1 Then
'Button2 will now react to all the events defined for 'test':
test = Button2
Else
'Button1 will now react to all the events defined for 'test':
test = Button1
End If
End Sub
End Class
I know that I can hard-code the event wireups in C#:
test.Click -= button_Click;
test = Button2;
test.Click += button_Click;
but obviously this becomes unworkable when you know that more event handlers
than just 'Click' are involved.
--
http://www.tangiblesoftwaresolutions.com
C++ to C#
C++ to VB
C++ to Java
Instant C#: VB to C#
Instant VB: C# to VB
Instant C++: VB or C# to C++/CLI
Java to VB & C# Converter: Java to VB or C#