Hi!
I'm trying to figure out how to create a control which can add or edit
code during drag&drop operation. I know how to handle CreateTransaction
method and add the control but I have no idea how to add event code
content during this operation.
For example, I would like to add the MyButton control which after drop
on Form will add Click event handler (+=new EventHandler to
ComponentDesigner generatated code) and put myButton_Click method with
some code inside.
I don't know if should I play with
System.CodeDom.CodeAttachEventStatement or maybe there is another
method?
I cannot find any example of such a thing. Sorry for my english :)
Mikolaj
Mujdat Dinc - 06 Apr 2005 14:47 GMT
Hi..
To bind an event this helps you..
You can do this in your customtoolitem on CreateComponentCore function or
set set on your componet or initilize on your designer...
IEventBindingService eventservice =
(IEventBindingService)this.Component.Site.GetService(typeof(System.ComponentModel.Design.IEventBindingService));
if( eventservice != null )
{
// Attempt to obtain a PropertyDescriptor for a
EventDescriptorCollection edc =
TypeDescriptor.GetEvents(this.Component);
if( edc == null || edc.Count == 0 )
return;
EventDescriptor ed = null;
foreach(EventDescriptor edi in edc)
if(edi.Name == "Click")
{
ed = edi;
break;
}
if( ed == null )
return;
// Use the IEventBindingService to get a
// PropertyDescriptor for the event.
PropertyDescriptor pd = eventservice.GetEventProperty(ed);
if( pd == null )
return;
// Set the value of the event to "testEventHandler".
pd.SetValue(this.Component, "testEventHandler");
}
----- Original Message -----
From: <fujiyama@gmail.com>
Newsgroups: microsoft.public.dotnet.framework.windowsforms.designtime
Sent: Wednesday, April 06, 2005 2:02 AM
Subject: Design Time event generation and method content
> Hi!
> I'm trying to figure out how to create a control which can add or edit
[quoted text clipped - 12 lines]
>
> Mikolaj