J
JaD
I am trying to understand events and delegates which is confusing me.
Okay I have a user control that derives from a GroupBox called (MyPanel)
I added this:
public delegate void Collapsed();
public event Collapsed OnCollapsed;
public void CollapseIt()
{
if (OnCollapsed!=null)
{
this.Height = this.Height - 10;
}
}
If someone calls CollapseIt() from a form (i.e. on the click event of a
button) the height of the GroupBox decreases correctly...
i.e:
private void button1_Click(object sender, System.EventArgs e)
{
c.CollapseIt();
}
I add "MyPanel" at run time and attach the Handler
private void Form1_Load(object sender, System.EventArgs e)
{
c = new MyPanel();
c.OnCollapsed+=new WindowsApplication2.MyPanel.Collapsed(c_OnCollapsed);
this.Controls.Add(c);
}
private void c_OnCollapsed()
{
MessageBox.Show("Collapsed Fired!") //<------------- THIS NEVER
FIRES!!!!!!! ? WHY?
}
Why does my MessageBox not show even if I called CollapseIt?
Okay I have a user control that derives from a GroupBox called (MyPanel)
I added this:
public delegate void Collapsed();
public event Collapsed OnCollapsed;
public void CollapseIt()
{
if (OnCollapsed!=null)
{
this.Height = this.Height - 10;
}
}
If someone calls CollapseIt() from a form (i.e. on the click event of a
button) the height of the GroupBox decreases correctly...
i.e:
private void button1_Click(object sender, System.EventArgs e)
{
c.CollapseIt();
}
I add "MyPanel" at run time and attach the Handler
private void Form1_Load(object sender, System.EventArgs e)
{
c = new MyPanel();
c.OnCollapsed+=new WindowsApplication2.MyPanel.Collapsed(c_OnCollapsed);
this.Controls.Add(c);
}
private void c_OnCollapsed()
{
MessageBox.Show("Collapsed Fired!") //<------------- THIS NEVER
FIRES!!!!!!! ? WHY?
}
Why does my MessageBox not show even if I called CollapseIt?