[Mono-list] Casting problem

Paul paul at all-the-johnsons.co.uk
Mon Mar 19 19:09:04 EDT 2007


Hi,

I'm trying to find a way to use one method to replace a number. I have
two menus, one for difficulty and the other chooses a test. If I wanted
to handle each menu click, I could use a whole pile of events, but I'd
rather use one which catches everything.

When I've done this sort of thing in VB, I've done something like
this...

Private Sub LotsOfButtons(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click, Button2.Click, Button3.Click
  Dim clickedCtrl As Control
  If TypeOf sender Is Control Then
    clickedCtrl = DirectCast(sender, Control)
    MsgBox(clickedCtrl.Text)
  End If
End Sub

Okay, DirectCast doesn't exist in C#. What would I need to use to
convert this over to C#? My current code is a bit of a mess

private void difficulty_Click(object sender, EventArgs e)
{
  int handle;
  Control ctl = new Control();
  if (sender is Control)    
   // at this point, I'd do the directcast
}

What do I need to do here?

TTFN

Paul
-- 
Sie können mich aufreizen und wirklich heiß machen!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://lists.ximian.com/pipermail/mono-list/attachments/20070319/1cb434f7/attachment-0001.bin 


More information about the Mono-list mailing list