"Jon Skeet [C# MVP]" <sk***@pobox.co m> a écrit dans le message de news:
11************* *********@g14g2 00...legr oups.com...
| I don't believe there's anything similar in the .NET framework.
| However, you could create a class which aggregated a list of controls,
| and allowed you to manipulate them (enable/disable etc) as a group
| (just by looping through the list when you asked the instance to do
| something).
Oleg, take a look at creating a Component derivative that implements
IExtenderProvid er. Make sure that it is capable of capturing the Click event
of Control. This will set you in a similar direction; I suggest that you
look at the source for TControl, TActionLink and TActionList to see how
Delphi works, and then simplify what you see.
Here's a starter :
[ProvideProperty ("InvokeAction" , typeof(Control) )]
public class ActionProvider : Component, IExtenderProvid er
{
private class Properties
{
private bool invokeAction = false;
public bool InvokeAction
{
get { return invokeAction; }
set { invokeAction = value; }
}
}
private Hashtable properties = new Hashtable();
private EventHandler execute;
public event EventHandler Execute
{
add { execute += value; }
remove { execute -= value; }
}
public ActionProvider( IContainer parent)
{
parent.Add(this );
}
bool IExtenderProvid er.CanExtend(ob ject obj)
{
return obj is Control;
}
private Properties EnsurePropertie sExists(object key)
{
Properties p = (Properties) properties[key];
if (p == null)
{
p = new Properties();
properties[key] = p;
}
return p;
}
[Category("Behav iour")]
[Description("Ca lls centralised event handler for Click event of linked
controls")]
[DefaultValue(fa lse)]
public bool GetInvokeAction (Control c)
{
return EnsurePropertie sExists(c).Invo keAction;
}
public void SetInvokeAction (Control c, bool value)
{
EnsurePropertie sExists(c).Invo keAction = value;
if (value)
c.Click += HandleClick;
else
c.Click -= HandleClick;
}
private void HandleClick(obj ect sender, EventArgs args)
{
if (!DesignMode)
{
Control control = (Control) sender;
if (control != null && execute != null)
{
execute(this, EventArgs.Empty );
}
}
}
}
Joanna
--
Joanna Carter [TeamB]
Consultant Software Engineer