引用:http://dotnet247.com/247reference/msgs/9/47826.aspx
I'm not sure why you can't modify the Text, but the Name property hasn't
been set up by the container yet in the process of adding so the
DesignerHost is probably just over-writing your value. You'd probably be
better trying to handle that rename in OnCompoentAdded.
IComponentChangeService is how you notify that a object has been changed.
Undo/redo relies on this, as does serialization. Say you were going to
change the Text property.
IComponentChangeService changeSvc =
(IComponentChangeService)GetService(typeof(IComponentChangeService));
try {
PropertyDescriptor prop =
TypeDescriptor.GetProperties(button1)["Text"];
string oldValue = button1.Text;
changeSvc.OnComponentChanging(button1,prop);
button1.Text = "Foo";
changeSvc.OnComponentChanged(button1, prop, oldValue, button1.Text);
catch (CheckoutException cex{
if (cex != CheckoutException.Canceled) {
throw cex;
}
}
It is very very important to balance OnComponentChanging/OnComponentChanged
calls for all actions you expect the designer to be aware of. If you need
to do multiple actions atomically, see IDesignerHost.CreateTrancaction and
DesignerTransactions.
--
This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. © 2001 Microsoft Corporation. All rights
reserved.
"NAG" <Click here to reveal e-mail address> wrote in message
news:OJAqrVmrBHA.2412@tkmsftngp03...