T
Tony Johansson
Hi!
Here I have two classes(Control and Button) that show how it might look like
in the .NET.
I have also a user defined class called MyExample that is using the Button
class.
I'm almost sure that only the class that contain the event can raise this
same event.
I have read this in a book so I hoped it's true ? So in this case only the
Control class can raise the Click event even if an object of a Button class
is used and the Click event is used.
In my user defined class instansiating a Button object and then use the
Click event so the event handler
ok_Click can be called when the user click on the button.
What I want to know is if anybody could give some example how the .NET
framework might look like to be able to raise
an event whan a Button object is using the Click event that is located in
the Control class ?
namespece System.Windows.Forms
{
public class Control
{
public event EventHandler Click;
. . .
}
public class Button : Control
{
...
}
}
class MyExample
{
private System.Windows.Forms.Button ok:
public MyExample()
{
ok.Click += new System.EventHandler(ok_Click);
}
private void ok_Click(object sender , System.EventArgs e)
{
. . .
}
}
//Tony
Here I have two classes(Control and Button) that show how it might look like
in the .NET.
I have also a user defined class called MyExample that is using the Button
class.
I'm almost sure that only the class that contain the event can raise this
same event.
I have read this in a book so I hoped it's true ? So in this case only the
Control class can raise the Click event even if an object of a Button class
is used and the Click event is used.
In my user defined class instansiating a Button object and then use the
Click event so the event handler
ok_Click can be called when the user click on the button.
What I want to know is if anybody could give some example how the .NET
framework might look like to be able to raise
an event whan a Button object is using the Click event that is located in
the Control class ?
namespece System.Windows.Forms
{
public class Control
{
public event EventHandler Click;
. . .
}
public class Button : Control
{
...
}
}
class MyExample
{
private System.Windows.Forms.Button ok:
public MyExample()
{
ok.Click += new System.EventHandler(ok_Click);
}
private void ok_Click(object sender , System.EventArgs e)
{
. . .
}
}
//Tony