[Mono-list] Casting problem

Juan C. Olivares juancri at gmail.com
Mon Mar 19 19:18:04 EDT 2007


private void difficulty_Click(object sender, EventArgs e)
{
    int handle;
    Control ctl;
    if (sender is Control)
        ctl = (Control) sender;
}

On 3/19/07, Paul <paul at all-the-johnsons.co.uk> wrote:
>
> 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!
>
> _______________________________________________
> Mono-list maillist  -  Mono-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list
>
>
>


-- 
Juan Cristóbal Olivares
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-list/attachments/20070319/20ef4476/attachment.html 


More information about the Mono-list mailing list