Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Designer Serializes dynamic created Controls
 

Designer Serializes dynamic created Controls

Hi,

my Situation is the following:

I have a conncectionManger class, that manages various Database Connections.
I am also working with a Ribbon UI, however the same concept would apply to Containers.

I am creating now a front end for this Connection Manager. The idea is to have a Component, lets call it cmComponent that has a property of type RibbonGroup, where it takes a ribbon group to wich it adds all the controls that are needed tomanagetheconnections.

The problem is now that these Controls are added to the group at runtime andtheDesignercreatesmembervarsandpropertyassignmentsforthesedynamicallycreatedControls,alsoitshouldnt.

The Controls are private members of the class and i tried marking them with the DesignerSerializationVisibility.Hidden Attribute. I had the impression it worked once but i never got it running again.

So what is the way to prevent the designer from serializing dynmaic created Controls?
Johannes Rudolph  Thursday, May 01, 2008 1:15 PM

Hi,

If the code in the InitializeComponent method has already been generated, you should remove it and add attribute for the corresponding properties in your control for testing. After that, if the code in InitializeComponentwon't exist, it indicates the approach is correct.

Please try to this.

Hope this can help you !

Regards,

Roy Zhou

Roy Zhou - MSFT  Wednesday, May 07, 2008 2:20 AM

anyone???

Johannes Rudolph  Saturday, May 03, 2008 9:49 AM

Add this Attribute

[ DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden) ]

Roy Zhou - MSFT  Tuesday, May 06, 2008 8:53 AM
as stated above, i already tried this but it didnt work.
Johannes Rudolph  Tuesday, May 06, 2008 1:51 PM

Hi,

If the code in the InitializeComponent method has already been generated, you should remove it and add attribute for the corresponding properties in your control for testing. After that, if the code in InitializeComponentwon't exist, it indicates the approach is correct.

Please try to this.

Hope this can help you !

Regards,

Roy Zhou

Roy Zhou - MSFT  Wednesday, May 07, 2008 2:20 AM

Hi,

Yes i tried removing the code and adding the attribute but it didnt work. Let me try to explain the situation a bit more in detail:

I have a Form, that has a ribbon group. I have a component that takes this ribbon group though a property.

I open the forms designer, initialize component (of the form) is called and creates a new instance of my component. In the Constructor of my Component the Button is created.
After that the assigner assigns:

Code Snippet

MyComponent.ribGroup = this.RibbonGroup1

now what happens in the class is:

Code Snippet

class MyComponent

{

[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]

private RibbonButton m_BtTest;

private RibbonGroup m_RibGr;

MyComponent()

{

m_BtTest = new RibbunButton();

}

public RibbonGroup ribGroup

{

get {return m_RibGr;}

set {m_RibGr = value;

m_RibGr.Items.Add(m_BtTest);

}

}

}

So the Button is now member of the Form1.RibbonGroup1.Items Collection. This Collection is Serialized by the Designer into InitializeComponent. This happens even though i marked my button with the [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] attribute.

Thanks for your interest and i hope you can help me.

Johannes Rudolph  Thursday, May 08, 2008 5:41 PM

This may be too late to help you, and you may have already found a solution, but from what I've found on this, I believe only publiic elements are serialized.

So, if you remove the DesignerSerializationVisibility attribute on the private property, and apply it to the public ribbon group (not the private), this should solve your issue. Again, I may be wrong on this, but it's what I'm doing in my stuff and it seems to work.

Also, depending on the IDE that you're using, you may have issues with the designer code updating itself. In the past, I've had to edit both the .designer and .resx files to get them to remove the serialization so I can mark the object properly.

If you've found the solution to your issue, please post it here so we can see how you've done it.

Thanks,

Mark

Mark Gerlach  Tuesday, July 01, 2008 2:44 PM

You can use google to search for other answers

Custom Search

More Threads

• Adding CheckedChanged event handler destroys my form, removing it instantly recovers my form
• Debugging WSOD
• how to open a form when click on custom property item in propertygridview
• Mysterious disappearing buttons
• Record locking Access 2002 Via VB .NET
• How to enlarge the size of the DataGridView's "Edit Columns" Dialog
• IDesignerHost Blocks Mouse Events
• Adding a dataset to DesignerHost
• VS2005 CryptographicException when adding SqlDataAdapter
• Draw Circle - urgent