Hi, I have a basic form with a button and a usercontrol (which is just a label).
What I want to do is when I click the button, raise a custom event and have the usercontrol listen out for it.
Any ideas how i can do this? I have got as far as this.
The Event
---------
using System;
using System.Collections.Generic;
using System.Text;
namespace Events
{
public class myEvent: EventArgs
{
private string _name;
public myEvent(string name)
{
_name = name;
}
public string Name
{
get
{
return _name;
}
}
}
}
UserControl
------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
namespace Events
{
public partial class myLabel : UserControl
{
public delegate void myEventHandler(Object sender, myEvent e);
public event myEventHandler someEvent;
public myLabel()
{
InitializeComponent();
this.someEvent += new myEventHandler(handleEvent);
}
void handleEvent(object sender, myEvent e)
{
MessageBox.Show("done");
}
}
}
THE FORM
---------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Events
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void simpleButton1_Click(object sender, EventArgs e)
{
}
}
}
What I want to do is when I click the button, raise a custom event and have the usercontrol listen out for it.
Any ideas how i can do this? I have got as far as this.
The Event
---------
using System;
using System.Collections.Generic;
using System.Text;
namespace Events
{
public class myEvent: EventArgs
{
private string _name;
public myEvent(string name)
{
_name = name;
}
public string Name
{
get
{
return _name;
}
}
}
}
UserControl
------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
namespace Events
{
public partial class myLabel : UserControl
{
public delegate void myEventHandler(Object sender, myEvent e);
public event myEventHandler someEvent;
public myLabel()
{
InitializeComponent();
this.someEvent += new myEventHandler(handleEvent);
}
void handleEvent(object sender, myEvent e)
{
MessageBox.Show("done");
}
}
}
THE FORM
---------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Events
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void simpleButton1_Click(object sender, EventArgs e)
{
}
}
}