Windows Develop Bookmark and Share   
 index > Windows Forms Designer > UserControl custom property and UndoEngine
 

UserControl custom property and UndoEngine

Hello,

I have a user control that has a custom property added to it. To make it simple the property is a bool. I have a basic implementation of UndoEngine that works fine.

When I delete a control from the design surface, and then "Undo" that, the Control comes back just fine, but the custom property is back to its default state. I've done quite a bit of research on things but haven't come up with anything helpful yet, so I'm here for more assistance from the experts.

I've played with the Localizable attribute for the property, but that doesn't work either.

Thanks again for the help.

Ken

Ken_Bussell  Monday, July 17, 2006 9:52 PM

Hi,

Without knowing your engine in detail, it is a bit tricky to say what's happening.

Make sure that:

1. You are setting properties within a transaction, and

2. That you set properties using TypeDescriptor.SetValue.

Hope that helps,

Martin

Martin Thorsen - MSFT  Monday, July 17, 2006 11:12 PM

Hi,

Without knowing your engine in detail, it is a bit tricky to say what's happening.

Make sure that:

1. You are setting properties within a transaction, and

2. That you set properties using TypeDescriptor.SetValue.

Hope that helps,

Martin

Martin Thorsen - MSFT  Monday, July 17, 2006 11:12 PM

I'm not totally sure I understand what you told me to do, but after some more looking into the problem, I think that setting the properties isn't where the problem is.

It looks like when the control is serialized, that the custom properties aren't serialized out with the ones like location, size etc. Do properties have to have special attributes for the serializer to serialize them?  I already have tried

[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]

[Localizable(true)]

But neither helped.  The ComponentSerializationService I registered was a new CodeDomComponentSerializationService.

OR do you have to save the properties that you want put back onto the control? For example I know that the text property isn't normally serialized because it is intended to be code set. But if you do an undo operation, it works just fine. So does the custom UndoEngine take care of that? (that was three questions sorry)

Ken_Bussell  Tuesday, July 18, 2006 2:47 AM

If the property doesn't serialize, have you tried adding a DefaultValue attribute? This attribute indicates to the designer that the value of the property is different than its default and should be serialized to code.

When are you setting the property value?

Benjamin Wulfe - MS  Tuesday, July 18, 2006 7:07 PM

Sorry for the delayed response.

I tried what you suggested and had the same results. However, I had a big ol message typed in, and then the reason this was happening occured to me.

I first create the object in the CreateComponentsCore method of my toolbox item. I then get that object and Modify its properties directly, by modifying the component that was returned to me by calling base.CreateComponentsCore. This happens after the component was created.

Now correct me if I'm wrong here in my thinking.

The UndoEngine records the event according to the Events of IComponentChangeService . So the state of my object would be recorded in the UndoEngine when the object was originally created. At that time my objects were at their default values.

If this is correct, then I need to change the default properties collection passed into CreateComponentsCore so that the object has the properties set when it is created so the UndoEngine will recognize them as being there.

Did I make any sense at all?

Ken_Bussell  Wednesday, July 19, 2006 12:57 AM

You can use google to search for other answers

Custom Search

More Threads

• Delete property value with custom UITypeEditor
• Design Time Controls
• Create a new ControlCollection in a Form in c#
• Custom COntrol versus User Control?
• Adding pre-created controls to a DesignSurface when hosting the Windows Forms Designer
• Adding a combobox to the statusbar ...
• PropertyGrid internals
• Method Not Found in Designer
• Unable to cast object of type X to type X after project rebuild
• TreeView owner draw