且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Windows窗体控件可以具有“仅设计时间”属性吗?

更新时间:2022-06-17 07:05:32

您可以通过为控件创建单独的设计器类。由于控件本身只能作为您的运行时实例存在,因此您不能真正在其上直接拥有仅在设计时设置的属性(它将存储在何处?)。但是,设计器类仅由设计器调用和使用,因此您可以在其中封装非运行时行为。

You can give a control design-time behavior by creating a separate designer class for the control. Since the control itself can only exist as an instance of your runtime, you can't really have a property directly on it which is set only at design-time (where would it get stored?). However, designer classes are only invoked and used by the designer, so you can encapsulate non-runtime behavior there.