如何让C#设计人员编辑我的struct属性? [英] How to let C# designer edit my struct property?
本文介绍了如何让C#设计人员编辑我的struct属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在C#中使用几个自定义属性创建一个自定义Windows窗体控件.这些属性之一是具有几个整数字段的简单结构:
I am creating a custom Windows Forms control in C# with several custom properties. One of those properties is a simple struct with several integral fields:
public struct Test
{
public int A, B;
}
Test _Test;
[Category("MyCategory")]
public Test TestProperty
{
get { return _Test; }
set { _Test = value; }
}
我希望Visual Studio设计人员以与 Size
, Margins
和其他类似Windows Forms结构相同的方式来编辑结构的字段.我是否需要基于 UITypeEditor
类实现自定义属性编辑器,还是.Net框架提供一些常用的结构编辑器"?
I want the Visual Studio designer to edit the fields of my structure the same way as it does for Size
, Margins
and other similar Windows Forms structures. Do I need to implement a custom property editor based on UITypeEditor
class, or is there some common "structure editor" provided by .Net framework?
推荐答案
这应该可以解决问题:
[TypeConverter(typeof(ExpandableObjectConverter))]
public struct Test
{
public int _A, _B;
public int B
{
get { return _B; }
set { _B = value; }
}
public int A
{
get { return _A; }
set { _A = value; }
}
}
Test _Test;
[Category("MyCategory")]
public Test TestProperty
{
get { return _Test; }
set { _Test = value; }
}
这篇关于如何让C#设计人员编辑我的struct属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文