防止 Visual Studio 设计器在创建时设置文本属性 [英] Preventing Visual Studio Designer from Setting Text Property on Creation

查看:26
本文介绍了防止 Visual Studio 设计器在创建时设置文本属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了 Visual Studio 设计器将 TextBox 中的文本设置为控件名称的约定问题.我有一个接受社会安全号码的控件,如果文本格式不正确(例如 123-45-6789 或 123456789),则覆盖 Text 属性以引发异常.当我尝试在设计器中使用该控件时,会引发此异常,因为 Visual Studio 试图将控件命名为 cssnTextBox1.我可以在 Text 属性上放置一个属性来防止设计人员设置它吗?

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?

推荐答案

看看这个讨论:如何在 C# 控件中检测设计时间.

Take a look at this discussion: how to detect design time in C# control.

http://vidmar.net/weblog/archive/2005/04/11/1246.aspx

如果控件的容器处于设计模式,您需要禁用 Text 属性验证.

You need to disable the Text property validation, if control's container is in design mode.

这篇关于防止 Visual Studio 设计器在创建时设置文本属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆