Windows窗体控件可以具有“仅设计时间”属性吗? [英] Can a Windows Forms control have a Design Time-only property?

查看:70
本文介绍了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?

推荐答案

您可以通过< a href = https://web.archive.org/web/20100402052134134/http://en.csharp-online.net/Design-Time_Integration%E2%80%94Design-Time-Only_Properties rel = nofollow noreferrer >为控件创建单独的设计器类。由于控件本身只能作为您的运行时实例存在,因此您不能真正在其上直接拥有仅在设计时设置的属性(它将存储在何处?)。但是,设计器类仅由设计器调用和使用,因此您可以在其中封装非运行时行为。

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.

这篇关于Windows窗体控件可以具有“仅设计时间”属性吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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