"Jon Skeet [C# MVP]" <sk***@pobox.com> a écrit dans le message de news:
11**********************@g14g2000cwa.googlegroups. 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
IExtenderProvider. 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, IExtenderProvider
{
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 IExtenderProvider.CanExtend(object obj)
{
return obj is Control;
}
private Properties EnsurePropertiesExists(object key)
{
Properties p = (Properties) properties[key];
if (p == null)
{
p = new Properties();
properties[key] = p;
}
return p;
}
[Category("Behaviour")]
[Description("Calls centralised event handler for Click event of linked
controls")]
[DefaultValue(false)]
public bool GetInvokeAction(Control c)
{
return EnsurePropertiesExists(c).InvokeAction;
}
public void SetInvokeAction(Control c, bool value)
{
EnsurePropertiesExists(c).InvokeAction = value;
if (value)
c.Click += HandleClick;
else
c.Click -= HandleClick;
}
private void HandleClick(object 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