Windows 窗体控件可以具有仅设计时属性吗?
我希望允许我的控件的用户选择控件的许可方法。选择来自枚举,因此他们必须选择我为他们列出的方法之一。需要在运行时执行代码之前选择此许可证。因此我希望他们在设计时选择一个值。此外,如果可以避免的话,我不希望该属性在运行时可写。有没有办法使属性仅在设计时可用?
I wish to allow the user of my control to choose the licensing method for the control. The choice comes from an enumeration, so they must choose one of the methods I have laid out for them. This license needs to be chosen prior to the code executing at runtime. Therefore I wish for them to selected a value at design time. Furthermore I do not wish for this property to be writable at runtime, if that can be avoided. Is there a way to make a property only available at design time?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过 为控件创建单独的设计器类。由于控件本身只能作为运行时的实例存在,因此您实际上不能直接在其上拥有仅在设计时设置的属性(它将存储在哪里?)。但是,设计器类仅由设计器调用和使用,因此您可以在那里封装非运行时行为。
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.