本文介绍了如何知道是否控制在设计时还是不是?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类(控制),实现ICustomTypeDescriptor,这是在设计时既使用和运行时间的PropertyGrid进行自定义。我需要公开在设计时不同的特性(标准控件,如 width属性高度等),并在运行时,当PropertyGrid中被用在我的计划,以改变控件的其他属性。

I have a class (control), implementing ICustomTypeDescriptor, which is used both at design-time and run-time by PropertyGrid for customization. I need to expose different properties at design-time (standard controls properties like width, height and so on) and at run-time, when PropertyGrid is used in my program to change other properties of that control.

我的code是这样的:

My code is like:

class MyControl : UserControl, ICustomTypeDescriptor
{
    //Some code..

    public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
    {
        return GetProperties();
    }

    public PropertyDescriptorCollection GetProperties()
    {
        //I need to do something like this:
        if (designTime)
        { //Expose standart controls properties
            return TypeDescriptor.GetProperties(this, true);
        }
        else
        {
            //Forming a custom property descriptor collection
            PropertyDescriptorCollection pdc = new PropertyDescriptorCollection(null);
            //Some code..
            return pdc;
        }
    }
}

有一个模拟的设计时标记在C#中?难道可能更好地使用条件编译?

Is there an analog for a design-time flag in C#? Is it maybe better to use conditional compilation?

推荐答案

检查的是真的还是假的。它是属于该控制基站类的属性。

Check if DesignMode is true or false. It's a property that belongs to the control base class.

这篇关于如何知道是否控制在设计时还是不是?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-18 18:04