Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Copy paste problems
 

Copy paste problems

Hello,

I am posting this question 2nd time in this post with a clearer picture of my problem below. Design guru's.... plzz give some light !!

I am using DesignSurface object to create a Form designer.

I drag and drop controls from the tool box on the design surface.

For control-drag, copy past functions, I am using CodeDomDesignerLoader

which implements the IDesignerSerializationService.

When I copy a resized control and paste it, it paste's it with the default size. i.e,

the control is created as a new instance instead of getting the cloned copy of

the existing control.

Please let me know how to overcome this problem

Also,

I found the DesignerSerializationManager class has a property

RecycleInstances which is default false, which means, it creates new instances

of the type every time. This is internally set to false whenever serialization and

deserialization occurs.

One way I see to overcome this problem is to set this property to true

However, I can't see any way to set this value as by the time I try to set this, the

object would be locked and no property values can be changed.

Am I missing any thing ? or we have some other way to achieve this.

Cheers,

mecspek

mecspek  Thursday, May 17, 2007 3:33 AM

Hey,
Thanx.. It worked....

Well, it was really a overkill....!! When I did not use the loader, the copy paste is happening with full speed !!

I guess it was probably due to reflection what CodeDomDesigner is used.

Thank you very much for your kind help..

Cheers,

mecspek.

mecspek  Friday, May 18, 2007 10:02 AM
What are you using to provide the ComponentSerializationService implementation? Your own class or CodeDomComponentSerializationService?
Malacki  Thursday, May 17, 2007 4:08 AM

I am using CodeDomComponentSerializationService.

& that is internally setting the DesignSerializationManager object RecycleInstances property to false.

mecspek  Thursday, May 17, 2007 6:40 AM

Hmm.

I'm not having your problem, but I don't use the CodeDomDesignerLoader (was overkill for what I needed.) I use CodeDomComponentSerializationService and the following implementation of IDesignerSerializationService. I noticed in another post that you use Reflector - maybe you can start with this code and, if it solves your problem, figure out why it fails when you use CodeDomDesignerLoader.

Code Snippet

Imports System.ComponentModel.Design.Serialization
Imports System.ComponentModel.Design
Public Class DesignerSerializationService
Implements IDesignerSerializationService

Dim serviceProvider As IServiceProvider


Public Sub New(ByVal ServiceProvider As IServiceProvider)
Me.serviceProvider = ServiceProvider
End Sub


Private Function GetService(ByVal svcType As Type) As Object
Return serviceProvider.GetService(svcType)
End Function


Private Function Deserialize(ByVal serializationData As Object) As ICollection Implements IDesignerSerializationService.Deserialize
Dim serializationSvc As ComponentSerializationService = GetService(GetType(ComponentSerializationService))
Dim designerHost As IDesignerHost = GetService(GetType(IDesignerHost))

If Not TypeOf serializationData Is SerializationStore Then Throw New ArgumentException("Deserialize: bad serialization store.")
If serializationSvc Is Nothing Then Throw New InvalidOperationException("Deserialize: unable to get a reference to ComponentSerializationService.")
If designerHost Is Nothing Then Throw New InvalidOperationException("Deserialize: unable to get a reference to IDesignerHost.")

Return serializationSvc.Deserialize(DirectCast(serializationData, SerializationStore), designerHost.Container)
End Function


Private Function Serialize(ByVal objects As ICollection) As Object Implements IDesignerSerializationService.Serialize
Dim serializationSvc As ComponentSerializationService = GetService(GetType(ComponentSerializationService))
Dim store As SerializationStore

If serializationSvc Is Nothing Then Throw New InvalidOperationException("Serialize: unable to get a reference to ComponentSerializationService.")

store = serializationSvc.CreateStore
If objects Is Nothing Then
For Each obj As Object In objects
serializationSvc.Serialize(store, obj)
Next
End If

store.Close()
Return store
End Function
End Class

Marc.

Malacki  Thursday, May 17, 2007 12:37 PM

Hey,
Thanx.. It worked....

Well, it was really a overkill....!! When I did not use the loader, the copy paste is happening with full speed !!

I guess it was probably due to reflection what CodeDomDesigner is used.

Thank you very much for your kind help..

Cheers,

mecspek.

mecspek  Friday, May 18, 2007 10:02 AM

Excellent, glad your problem is fixed.

Yeah I found the CodeDomDesignerLoader very slow with copy / paste. Using a straigh IDesignerSerializationService imlementation is nice and fast.

Marc

Malacki  Friday, May 18, 2007 12:26 PM

Guys,

For some time I am struggling to implement Copy Paste functionality in Custom Form Designer. I can understand part of the code posted here but still not able to implement the complete chain. It would be a great help if someone can pass some sample project with Copy Paste functionality to s_venky_in@hotmail.com

Thanks,

Venky

s_Venky  Thursday, June 21, 2007 11:16 AM

Hi,

I implemented a winform designer and used a loader derived from CodeDomDesignerLoader. I have also problems with copy/paste. I can copy and paste components, but the properties Backcolor, Forecolor, font, location and sizewill not be copied.

Is there is a possibility to serialize these properties too??

Can't you send me an example of a implementation?

Thank you very much.

robert

robert r  Monday, July 09, 2007 12:06 PM
Hi there,

I'm another one of those space-lost developers when it comes to Custom Form Designers.
I've started a Form Designer in the beginning of this week and it all worked fine and fast. All until yesterday when I implemented a Copy/Paste for my Designer 8->
It does copy/paste the control/s I want but I get the default properties and moreover, the same names!!!
I do implement the INameCreationService and it seems to give the control a unique name but when I save the current document, that name just isn't anymore. And I get N Buttons named "button1".....
My problem is that I don't know what my problem is ... I use a IDesignerSerializationService implementation for saving/loading the designed form and a CodeComSerializationService for copy/paste. Is that wrong?

Please help me, designer gurus!!!!!
Ingheţata Ta  Friday, March 20, 2009 12:27 PM
@ 7Turturi

I got the same problem, i solved that in this way.
In the IDesignerSerializationService.Deserialize you may have a link to your hosting designer & loader.
In your loader inside your "CreateObject" void you initialize some properties of your new Component, after the add on the Host.Components list you can set the Name Property re-calling your INameCreationService.

I hope to be clear >_>.

Campa  Wednesday, March 25, 2009 4:40 PM
tried that and it still does the same thing. managed to watch the creation of a pasted control. it does appear to be created with a different name. it is added to its container with that different name. but when saving the designer, it has the same name as its original. still don't know what could be the problem.

it seems that the problem comes from saving the designer. a copied component has the same site.name as its original. trying to fix something there.
7 Ţurţuri  Wednesday, April 01, 2009 9:34 AM
I am running into the exact same problem. When I call the CodeDomComponentSerializationService.Deserialize, the CreateObject is called from my designer host. The new control gets a new name correctly. But by the time the Deserialize Method completes, the new control gets the old control's name again. Any help would be appreciated.
dgc2  Tuesday, June 02, 2009 4:02 PM

You can use google to search for other answers

Custom Search

More Threads

• To open a Form
• Transparent layer control
• Docking and Stacking
• Can not add custom control to toolbox
• I 'm having a problem with my User Control
• How to get short keys on windows forms in C#.net 2005?
• Winform for GUI developmwnt
• How to add a user control to a DatagridView
• Adding a world map to windows form and connect locations with lines
• 2 WinForm bugs