Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Custom DocumentDesigner for a Windows Form and some issues
 

Custom DocumentDesigner for a Windows Form and some issues

Hello guys,

I have managed to create a custom design time support for my Windows Form by inheriting from the DocumentDesigner class and implementing the functionality found in FormDocumentDesigner (since the class is internal it cannot be inherited) so that the default design time behavior for a form is not broken. In my custom designer class I am overriding the Initialize method to create a new ToolStrip control and add it to the Controls collection of the form which works just fine. However, when closing the Form while in design time and reopening it, a new ToolStrip instance is created and added to the Controls collection, i.e. each time I close and reopen the designer of the form the amount of ToolStrip controls grows.

My question is how can I check whether there is already a ToolStrip control when the Initialize method of the designer is called so that I prevent this undesired behavior?

Is there a way to find out that there is a ToolStrip component already serialized in the code and thus avoiding the initialization of another one?

Thanks for your time!
WorldIntruder  Monday, May 25, 2009 3:45 PM
Hello Bruce,

In fact, I found out a way to prevent another ToolStrip from being added when the designer of the Form is reopened. I am using the LoadComplete event of the Form and at this point I am able to read the Controls collection of the Form and see wether there is a ToolStrip already. However, in the Initialize method that was not possible hence the Controls collection still wasnot filled with what is serialized in the Designer.cs file.

Thanks for your reply.
WorldIntruder  Sunday, May 31, 2009 1:52 PM
Hi WorldIntruder,

I'd like to know why you need to add the control in the initialize method of the designer. If you check the count of the controlcollection before adding the ToolStrip control, does it work?

If the above doesn't work, I think using a text file to store the information will be Ok. The text file will contain a line of string, which can be simply 0 at first. After we execute the code in the initialize method, we write 1 to the file. At last we add a "if statement" to determine whether to add the toolstrip control.

If you have any doubts, please feel free to let me know.

Best regards,
Bruce Zhou
Please mark the replies as answers if they help and unmark if they don't.
Bruce.Zhou  Friday, May 29, 2009 9:07 AM
Hello Bruce,

In fact, I found out a way to prevent another ToolStrip from being added when the designer of the Form is reopened. I am using the LoadComplete event of the Form and at this point I am able to read the Controls collection of the Form and see wether there is a ToolStrip already. However, in the Initialize method that was not possible hence the Controls collection still wasnot filled with what is serialized in the Designer.cs file.

Thanks for your reply.
WorldIntruder  Sunday, May 31, 2009 1:52 PM

You can use google to search for other answers

Custom Search

More Threads

• Making my own Grid - Problems
• Auto Format
• 'System.Windows.Forms.Label' does not contain a definition for 'PreferredHeight'
• Disabling datagridview column
• Using Web Form Designer in a Windows Form Application
• Designer auto assigning bogus string resource values
• Public statusstrip in base winform is not accessible in derived form?
• I can't see all form
• how to open instance of Ms Project
• Problem Updating .resx file