Windows Develop Bookmark and Share   
 index > Windows Forms General > Custom controls not keeping state
 

Custom controls not keeping state

Good time of Day,

I have a very simple custom control comprised of a label and a textbox. I have public accessor methods to change the textbox and label color, text, etc... When I place my custom control on a form and change, lets say the textbox's color within it, I can see the color change in the design mode. But, as soon as I compile the project, or close and open the form - the color is reset back to just white.

How can I make the custom control to persistently retain its properties?

Thanks,

-igor

imanassypov  Friday, October 27, 2006 1:33 PM
You need to create a property for every property that you want to store in designer code. So for example you will have TextBoxBackColor property that when setted will change textbox back color. By default when you create a property for UserControl, that property will be stored in designer code. If you want to disable that, because sometime that is also neccesarry, then you should use property attribute DesignerSerializationVisibility.
boban.s  Saturday, October 28, 2006 3:00 PM
You need to create a property for every property that you want to store in designer code. So for example you will have TextBoxBackColor property that when setted will change textbox back color. By default when you create a property for UserControl, that property will be stored in designer code. If you want to disable that, because sometime that is also neccesarry, then you should use property attribute DesignerSerializationVisibility.
boban.s  Saturday, October 28, 2006 3:00 PM

You can use google to search for other answers

Custom Search

More Threads

• validating xml without specifying xsd location in xml
• getting rid of textbox "flicker"
• Add a user Control and insert line of code
• Threads
• loading a browser in a pane or the likes of it
• how to open MdiChild from another MdiChild
• Save Before Exit?
• Form_FormClosing behavior
• Send WM_REFLECT + WM_... or just WM_...?
• Application Directory