Java to C#....

  • Thread starter Thread starter genc_ ymeri at hotmail dot com
  • Start date Start date
G

genc_ ymeri at hotmail dot com

Hi,
How can I translate this method in C# ?


public void actionPerformed (ActionEvent event)
{
if even.getSource() == mybtn
{
sayHello();
}
}

Thanks in advance.
 
Hi,
How can I translate this method in C# ?


public void actionPerformed (ActionEvent event)
{
if even.getSource() == mybtn
{
sayHello();
}
}

Thanks in advance.

This looks like a Java listener (I haven't done Java is several years
now, so I could be wrong :)...

Anyway, that would be a click evnet in C#....

So, you would have something like:

mybtn.Click += new EventHandler (actionPerformed);

private void actionPerformed (object sender, System.EventArgs e)
{
sayHello ();
}

Of course, you can hook this to more then one button, so you might have
something like:

private void actionPerformed (object sender, System.EventArgs e)
{
if (sender == mybtn)
{
sayHello ();
}
}

HTH
 
Well, probably I missed your point but to me it seems like it's not quite
the same though. In other words, is there anyaway in C# I can retrieve all
the events that fired from any possible control within a form and
discreminate them from the source without assigning the handler to the
controls (the source) ?????

Thanks.
 
genc_ ymeri at hotmail dot com said:
Well, probably I missed your point but to me it seems like it's not quite
the same though. In other words, is there anyaway in C# I can retrieve all
the events that fired from any possible control within a form and
discreminate them from the source without assigning the handler to the
controls (the source) ?????

No, you can't do that in C#. It's not a terribly nice way of writing UI
code though - and it's one which even in Java isn't the normal way of
doing things any more.

In C#, you subscribe to individual events. Several events can have the
same handler, and you can tell which control fired the event using the
sender parameter, but you can't (easily, anyway) say "give me all
events for all controls on this page".
 
Greatly appreciated !


Jon Skeet said:
No, you can't do that in C#. It's not a terribly nice way of writing UI
code though - and it's one which even in Java isn't the normal way of
doing things any more.

In C#, you subscribe to individual events. Several events can have the
same handler, and you can tell which control fired the event using the
sender parameter, but you can't (easily, anyway) say "give me all
events for all controls on this page".
 
Back
Top