I'd like to pre-populate some properties of a control when drag'ndrop from the toolbox onto the custom designer. When should I set these properties During the onselection, drag event, or somewhere else
Thanks,
Alan
I'd like to pre-populate some properties of a control when drag'ndrop from the toolbox onto the custom designer. When should I set these properties During the onselection, drag event, or somewhere else
Thanks,
Alan
When/Where should I instantiate the control when placing on the designer
Harry
I'll try as you suggested and post my experience.
Alan
KluchDev
Martin,
Thanks for your reply. I think that implementing a Behavior is overkill for what I want to do. I have figured out a simpler way to achieve the results I want. I'll try to explain what I am doing in case anyone else is having the same problem.
What I am trying to do is initialize the properties of a new control dropped on my design surface based on properties that are set in the toolbox item. As a convenience to the user, I would like my toolbox to support several toolbox items that are of the same type, but have different properties pre-set. (An example would be the ablility to drop a solid label, a striped label, or a polka-dot label from the toolbox.)
My control toolbox item is derived from ToolboxItem. I have added the properties that I want to set to my toolbox item. I have overriden ToolboxItem::OnComponentsCreated. In this method, I can get access to the new component, and initialize the necessary properties from the properties that I set in toolbox item.
Paul Becker
Hi Martin,
I am try to solve the same problem. I only want to initialize the properties when a toolboxitem is dropped. In the ComponentAdded event handler I can't distinguish between a toolboxitem drop, a paste, and a redo operation.
BrianCo
I have a further question: When placing a control on a tablelayoutpanel during design-time, say I'd like to set the control's initial columnspan to 3. When the componentadded event fired, the tablelayoutpanel is not visible to the component via Parent property yet, how can I set the columnspan for the added control then I tried to set it in the OnSelectionContentsChanged and it works. But I lose the capability to change it later on as the columnspan is set to the same value every time the control is selected. Martin, where should I set this property in this case
Thanks,
Alan
Orbix
Alan,
I started off with the MSKB example, and moved to using the new DesignSurface.
If you are using the MSKB example and a custom toolbox item, you need to update the serialization/deserialization code of the toolbox item in the toolbox service so that you serialize as a "MyToolboxItem" instead of a "ToolboxItem". Please see this bug report for more details: http://lab.msdn.microsoft.com/ProductFeedback/viewfeedback.aspx feedbackid=bb7ea307-dcda-4b07-b7ad-8f47328ca45e
Another (silly) problem that I had was that initially I had left the example code that called "new ToolboxItem(typeof(myItem))". This obviously did not create the correct ToolboxItem for my control. When I changed the code to create a "MyToolboxItem" explicitly everything worked fine.
erickson777
Hi,
You should be able to hook ComponentAdded using the IComponentChangeService.
Supergrover
That is totally what you want to do. It wasn't clear to me that you were dragging your own ToolboxItem, but that you wanted a generic solution.
Had I only known....
Christophe Goffin
That's it. Thanks Martin.
Eyvind
What you want to do is to install a global Behavior. Check out http://msdn2.microsoft.com/en-us/library/system.windows.forms.design.behavior(VS.80).aspx.
Make sure you call the constructor with callParentBehavior = true.
Then use the BehaviorService to push this behavior onto the behavior stack (check out PushBehavior on the BehaviorService).
Check out the methods on Behavior. E.g. you can override OnDragEnter. To check if you are dragging from the toolbox, you can call ToolboxService.DeserializeToolboxItem(DragEventArgs.Data, DesignerHost). If this returns a non-null object, then you are dragging from the toolbox. You can then set a global flag, check it in ComponentAdded, and clear it there as well.
MariaR
the link provided for the behavior service appears to be dead.
I found this white paper written by Jim Galasyn that is supposed to have info on Behavior services. I haven't read it yet but i wanted to post the link before I forgot.
http://msdn.microsoft.com/library/default.asp url=/library/en-us/dnvs05/html/DSExtend.asp
You can view Jim’s blog here
http://blogs.msdn.com/jgalasyn/archive/2006/08/21/711311.aspx
On a side note, does any one know if we are going to be able to host our own WPF designer when 3.0 comes out
On another side note, has any one else noticed that the windows workflow foundation acronym has been shorted to wf Is that because trademark issues with using WWF :)
macuman
This is going to be really tricky. The problem is that the TableLayoutPanelDesigner hooks OnControlAdded on the TableLayoutPanel. In this method, we set ColumnSpan/RowSpan to 1. ComponentAdded is called before OnControlAdded, so even if there was a way to do it in ComponentAdded, it would get overriden later.
I am not sure I understand your scenario, but you could do something really hacky:
1. Install a global Behavior (see other post to this thread).
2. Override OnDragDrop. In here you first call base.OnDragDrop. Remember the control you added (you can do that in ComponentAdded).
3. Back in your OnDragDrop, once you get back, you can now set the RowSpan/ColumnSpan.
I think that should work.
Martin
Marc Kuperstein - MSFT
Brenzy,
I tried to do the same thing a while ago. But somehow that the toolboxitem of the control never worked (seems not attached) on my custom designer. It works within VS IDE. Seems I'm missing some service. I'm using the MSKB 2004 example as a testing environment. Are you using the new designsurface instead of implementing IDesignerHost Do you have any suggestion on this
Thanks,
Alan