在设计模式不知何时 [英] Knowing when in design mode

查看:123
本文介绍了在设计模式不知何时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从一个类库,我想知道这是否是在设计模式,而不是正常运行时被访问。

From within a class library, I'd like to know if it is being accessed during design mode as opposed to normal runtime.

我试图用System.ComponentModel.LicenseManager.UsageMode但它似乎有运行时的值,即使我编辑的一种形式。

I tried using System.ComponentModel.LicenseManager.UsageMode but it seemed to have a value of Runtime even when I was editing a form.

更新: 为了澄清,我想知道我是否在设计模式不是从一个组件中,而是来自内部,恰好从一个表单或控制范围内的其他项目被称为一个单独的类。我有正从控制间接调用的一个实用工具类,它是存在的,我需要知道,如果我在设计模式或没有。

UPDATE: To clarify, I want to know if I am in design mode not from within a component, but rather from within a separate class that happens to be called by other items from within a form or control. I have a Utility class which is being called indirectly from a control and it is there that I need to know if I am in design mode or not.

推荐答案

我不认为Component.DesignMode会在这种情况下提供帮助。如果什么组件或控件未在窗体设计器加载?在此情况下,可以尝试是,创建一个枚举,只有设置在正常启动的一个值,否则仍然在默认情况下另一个值是什么。现在,您可以检查枚举实例的值,并决定如果它是一个设计时或运行时。

I don't think Component.DesignMode will help in this case. What if the component or control is not loaded on the forms designer ? What you may try in this case is, create an enum that only sets the one value at normal startup which otherwise remains to another value by default. You can now check the value of the enum instance and decide if it's a design-time or runtime.

这篇关于在设计模式不知何时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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