"Kim" <(E-Mail Removed)> a écrit dans le message de news:
(E-Mail Removed)...
| Joanna: Think I get the idea, but I under what you mean with "Create a
| new public event on the form that can be caught in the outside class".
| Could elaborate it ?
public partial class Form1 : Form
{
...
#region public event
private EventHandler button1Clicked;
public event EventHandler Button1Clicked
{
add { button1Clicked += value; }
remove { button1Clicked -= value; }
}
#endregion
private void button1_Click(object sender, EventArgs args)
{
if (button1Clicked != null)
{
button1Clicked(sender, args);
label1.Text = "some value";
}
}
}
public class Stuff
{
private void HandleForm1Button1Click(object sender, EventArgs args)
{
// do something
}
public void ShowForm()
{
Form1 test = new Form1();
test.Button1Clicked += HandleForm1Button1Click;
test.Show;
}
}
But better still would be to pass an instance of Stuff to the constructor of
the form, then your event handlers can work directly on the object.
public partial class Form1 : Form
{
...
private Stuff stuff;
public Form1(Stuff stuff)
{
this.stuff = stuff;
}
private void button1_Click(object sender, EventArgs args)
{
stuff.DoSomething();
label1.Text = "some value";
}
}
}
Joanna
--
Joanna Carter [TeamB]
Consultant Software Engineer