Windows Develop Bookmark and Share   
 index > Windows Forms Designer > How to modify the ToolBoxItem.CreateComponentsCore defaultValues parameter
 

How to modify the ToolBoxItem.CreateComponentsCore defaultValues parameter

ToolBoxitem has a CreateComponents core method and one of the parameters is a set of Default Values that the ToolBox uses to setup the control it will create.

How can I modify what is passed into there BEFORE this method is called?

My design surface is based off of Form. I would like to override the method where the drop happens and the create components core is called. I've looked at the call stack for this and there are about 15 things that happen before it gets to this method, so I'm not sure where to jump in (or if I even can)

Thanks for the help.

Ken_Bussell  Thursday, July 20, 2006 2:39 PM

You should set the properties using TypeDescriptor.SetValue. Let me know if that solves you problem.

Martin

Martin Thorsen - MSFT  Thursday, July 20, 2006 7:33 PM

Hey,

From looking at the code, it doesn't seem like it is possible.

What's your scenario?

Martin

Martin Thorsen - MSFT  Thursday, July 20, 2006 5:21 PM

Well this has a little to do with my other post http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=561209&SiteID=1

Every example I've seen so far has you add the object to the design surface, then modify its properties. The problem comes in with the UndoEngine. This is the sequence I've seen

1. Drop a ToolBoxItem onto the design surface

2. UndoItem is created for that object.

3. CreateComponentsCore is called - this is where I set the properties I want.

This works fine. However, lets say I do an Undo which removes the object) then aRedo(which puts it back on the form)right after I add the object to the form. What I've noticed is that the properties I've set are back to their default settings. This means one of two things. Either the UndoItem has the state the object was originally stored in it OR the object is created NEW when it is put back on the form.

In addition to this scenerio, I'm concerned about what happens when I Delete an object from the design surface and then Undo that. Will the object come back as it was, or will it be new? I'm still working on getting this to work though so I haven't found out yet.

I don't mind turning off the undo engine (enabled = false) for when I add a new object, but I'm really worried about the delete.

Ken_Bussell  Thursday, July 20, 2006 6:51 PM
When you redo, is the Location property set correctly? I.e. try and drop the item at the bottom right of the form. Is it only the properties that you set that get the default values? If so, how are you setting them?
Martin Thorsen - MSFT  Thursday, July 20, 2006 7:02 PM

Yes the location and size are correct. It is only the custom properties that I set that are set back to default. I am setting the properties directly like components[0].Text = "HELLO"; after the object is created.

Now if I move the object around and play with it, and undo that, the properties are fine. Probably becuase the object isn't totally removed from the surface like in my example.

Does the UndoUnit actually store a complete serialized representation of an object when it (the undo unit)is created? I ask because this would make sense of what is happening. One thing I don't want to have happen is when I add an object and modify its propteries right then, that a separate undo unit is created for each modification. Basically if the user adds an object to the screen accidentally, I don't want them to have to undo 16 things to get the object to go away.

Ken_Bussell  Thursday, July 20, 2006 7:29 PM

You should set the properties using TypeDescriptor.SetValue. Let me know if that solves you problem.

Martin

Martin Thorsen - MSFT  Thursday, July 20, 2006 7:33 PM

You've said this before and I guess it hasn't sunk in yet. I'll play with it and update the answers if it works.

Thanks.

Ken

Ken_Bussell  Thursday, July 20, 2006 7:36 PM

You can use google to search for other answers

Custom Search

More Threads

• Find controls on a windows form
• Composite Control and Click Event
• DataGridView - different color in the same cell , e.Handled problem
• Tab and menustrip controls
• ListView columns property is readonly and disabled in Form designer
• Resources NOT applied on localizable form. I have to manually edit the form at design time for them to be applied.
• Receiving Form Designer Error: "Type 'mpx.Controller' does not have a constructor with parameters of types DesignerHost."
• listbox ownerdraw doesn't redraw when multiselect is on
• How to get Special Folder Icons??
• Error in Updating database table using OdbcDataAdapter.Update() method