Implementing this interface means defining tons of events that don't really
have anything to do with the component - and then writing an event handler?
I looked at classes like the DataSet - which creates DataTable's in the
designer. It does not implement this interface.
I am still at a loss at how to actually have the code for these components
removed from the designer.
Is there a complete example I can look at?
Thanks
> Hi, Marina!
>
[quoted text clipped - 26 lines]
> > Thanks,
> > Marina
Marina - 14 Jun 2004 17:55 GMT
Found an example, here is the thread in case anyone is curious:
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&threadm=usZytQPpBHA.2172%40tk
msftngp03&rnum=1&prev=/groups%3Fhl%3Den%26lr%3D%26ie%3DUTF-8%26selm%3DusZytQPpBH
A.2172%2540tkmsftngp03
> Implementing this interface means defining tons of events that don't really
> have anything to do with the component - and then writing an event handler?
[quoted text clipped - 43 lines]
> > > Thanks,
> > > Marina
DRaiko - 15 Jun 2004 08:51 GMT
Halt! Halt!
Marina! You need not implement interfaces. Everything is already there.
Ten lines are enough. (well, 20).
(i) Override the Site Property of component A:
public override ISite Site{
get{ return base.Site; }
set{
// get change service
IComponentChangeService chServ = (IComponentChangeService)base.GetService(
typeof( IComponentChangeService));
if( chServ != null){
// may be not the 1st setter call, so unhook:
chServ.ComponentRemoved -= new ComponentEventHandler( chServ_Removed);
}
base.Site = value;
// get anew (the Site is different)
chServ = (IComponentChangeService)base.GetService(
typeof( IComponentChangeService));
// hook
if( chServ != null){
chServ.ComponentRemoved += new ComponentEventHandler( chServ_Removed);
}
}
}
(ii) handle removing:
private void chServ_Removed( object sender, ComponentEventArgs e){
IDesignerHost desHost = (IDesignerHost)sender;
if( desHost.Loading)
return; // all components are removed when designer unloads.
// Ignore in this case. ---------->>>>>>>>>>>>>
if( object.ReferenceEquals( e.Component, this)){
// yes, they want to kill me! Imust kill all my children.
foreach( B b in b_collection){
desHost.DestroyComponent( b);
}
// unhook
IComponentChangeService chServ = (IComponentChangeService)base.GetService(
typeof( IComponentChangeService));
if( chServ != null){
chServ.ComponentRemoved -= new ComponentEventHandler( chServ_Removed);
}
}
}
(iii) be happy.
Check for typos, but the idea must be clear.
It would be better to enclose removing all b-components in one transaction.
(mainly to be able to undo removing in one click).
If i understand what you need.
HTH,
Dima.
> Implementing this interface means defining tons of events that don't really
> have anything to do with the component - and then writing an event handler?
[quoted text clipped - 43 lines]
> > > Thanks,
> > > Marina