选择多个项目时如何显示自定义字符串?

发布于 2024-07-15 01:48:03 字数 1352 浏览 8 评论 0原文

我有一个属性网格,可以帮助我管理表单上的所有控件。 这些控件适用于设计师类型的人员,因此我并不真正担心用户界面......直到有人选择多个对象。

我有一个用于这些常见对象上的“EffectiveDiameter”属性的 UITypeEditor。 它跟踪单位(米与英尺)并即时执行一些不错的操作。 但是,当某人选择两个或三个常见对象时,EffectiveDiameter 为空,即使它计算结果为相同的文本字符串。

例如,在大多数控件中,Microsoft 具有“Anchor”属性,其文本输出为“Top, Right”。 当你把它拉下来时,它是一个带有漂亮 UITypeEditor 的对象。 然而,当您在表单上选择五个具有相同锚点设置的对象时,您仍然可以在属性网格中看到字符串“Top, Right”。

/// <summary>
/// The default containing class for all Unit-Management Conversion classes.
/// </summary>
[
 Serializable,
 EditorAttribute(typeof(umConversionTypeEditor), typeof(UITypeEditor)),
 TypeConverter(typeof(umConversionTypeConverter)),
]
public class umConversion
{
    ...
}


public class umConversionTypeEditor : UITypeEditor
{
    ...
}



// Now, in my designer class, I have ...
private double _effectiveDiameter { get; set; }

[DisplayName("Effective Diameter")]
public virtual umConversion EffectiveDiameter
{
    get
    {
            umConversion ret = new umConversion (_effectiveDiameter);
            ret.MeasureInSI = _si;
            return ret;
        }
        set
        {
           _effectiveDiameter = value.ImperialUnits;
        }
    }
}

如果我选择多个自定义对象(所有对象都具有相同的有效直径),如何才能像 Anchor 一样在 PropertyGrid 中显示有效直径? 目前,该字段始终为空白。

I have a property grid that helps me manage all of the controls on a form. These controls are for designer-type folks, so I'm not really worried that much about the user interface... until someone selects multiple objects.

I have a UITypeEditor for the "EffectiveDiameter" property on these common objects. It keeps track of units (meters vs feet) and does some nice things on-the-fly. However, when someone selects two or three common objects, EffectiveDiameter is blank, even though it evaluates to the same text string.

For example, in most controls, Microsoft has the "Anchor" property that has a text output of "Top, Right". When you pull it down it is an object with a nice UITypeEditor. Yet, when you select five objects on your form that all have the same Anchor setting you can still see the string "Top, Right" in the property grid.

/// <summary>
/// The default containing class for all Unit-Management Conversion classes.
/// </summary>
[
 Serializable,
 EditorAttribute(typeof(umConversionTypeEditor), typeof(UITypeEditor)),
 TypeConverter(typeof(umConversionTypeConverter)),
]
public class umConversion
{
    ...
}


public class umConversionTypeEditor : UITypeEditor
{
    ...
}



// Now, in my designer class, I have ...
private double _effectiveDiameter { get; set; }

[DisplayName("Effective Diameter")]
public virtual umConversion EffectiveDiameter
{
    get
    {
            umConversion ret = new umConversion (_effectiveDiameter);
            ret.MeasureInSI = _si;
            return ret;
        }
        set
        {
           _effectiveDiameter = value.ImperialUnits;
        }
    }
}

If I select several of my custom objects -- all with the same effective diameter -- how do I get EffectiveDiameter to display in the PropertyGrid like Anchor does? Right now, that field is always blank.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

献世佛 2024-07-22 01:48:04

从您的描述看来您正在谈论 double 类型的 effectiveDiameter 。 但在您的示例中,您显示了 umConversion 类的 UITypeEditor。 所以,请澄清一下。

如果您处于第二种情况,您的属性实际上是您自己的类而不是原始类型,那么请确保实现 Equals 方法。 MS PropertyGrid 中的 MultiPropertyDescriptorGridEntry 类调用 Equals 来了解所有目标实例是否具有相同的值。 不确定这是否是您的问题,但我会测试以消除这种可能性。

From your description it seems you are talking about the effectiveDiameter of type double. But in your sample you are showing a UITypeEditor for the umConversion class. So, please clarify.

If you are in the second case, where your property is actually a class of your own and not a primitive type, then ensure to implement the Equals method. The MultiPropertyDescriptorGridEntry class in the MS PropertyGrid calls Equals to know if all target instances have the same value. Not sure if this is your problem, but I would test that to eliminate this possibility.

勿忘初心 2024-07-22 01:48:04

还在每个属性上放置一个 TypeConverter 属性。

Place a TypeConverter attribute on each property too..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文