I've got a problem with Visual Studio Designer's convention of setting the text in a TextBox to the name of the control. I've got a control that accepts a Social Security Number, and the Text property is overridden so as to throw an exception if the text is not in the correct format (e.g. 123-45-6789 or 123456789). When I try to use the control in the designer, this exception is thrown because Visual Studio is trying to name the control cssnTextBox1. Is there an attribute I can place on the Text property to prevent the designer from setting it?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Take a look at this discussion: how to detect design time in C# control.
http://vidmar.net/weblog/archive/2005/04/11/1246.aspx
You need to disable the Text property validation, if control's container is in design mode.