저는 .NET/C# expert는 아니지만 System.Drawing.Point
클래스의 TypeConverterAttribute
으로 사용되는 PointConverter
클래스의 어딘가에있는 것으로 보입니다. 컬렉션 편집기는 실패한 PointConverter
클래스 내의 무언가를 사용해야합니다.
PointF
클래스에 TypeConverterAttribute
이 없으므로 PointConverter
으로 의심됩니다. 제대로 작동합니다. 모음에 Point
클래스를 사용할 때이 MSDN에서 몇 가지 코드를 사용하여 함께 자갈길 다음 예에서
는 문제가 아니라 사용자 정의
TypeConverter
를 사용하는
MyPoint
클래스, 볼 수 있습니다.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Globalization;
namespace WindowsControlLibrary1
{
public class MyTypeConverter : TypeConverter
{
// Overrides the CanConvertFrom method of TypeConverter.
// The ITypeDescriptorContext interface provides the context for the
// conversion. Typically, this interface is used at design time to
// provide information about the design-time container.
public override bool CanConvertFrom(ITypeDescriptorContext context,
Type sourceType)
{
if (sourceType == typeof(string))
{
return true;
}
return base.CanConvertFrom(context, sourceType);
}
// Overrides the ConvertFrom method of TypeConverter.
public override object ConvertFrom(ITypeDescriptorContext context,
CultureInfo culture, object value)
{
if (value is string)
{
string[] v = ((string)value).Split(new char[] { ',' });
return new MyPoint(int.Parse(v[0]), int.Parse(v[1]));
}
return base.ConvertFrom(context, culture, value);
}
// Overrides the ConvertTo method of TypeConverter.
public override object ConvertTo(ITypeDescriptorContext context,
CultureInfo culture, object value, Type destinationType)
{
if (destinationType == typeof(string))
{
return ((MyPoint)value).X + "," + ((MyPoint)value).Y;
}
return base.ConvertTo(context, culture, value, destinationType);
}
}
[SerializableAttribute]
[TypeConverterAttribute(typeof(MyTypeConverter))]
public struct MyPoint
{
private int x;
private int y;
public MyPoint(int _x, int _y)
{
x = _x;
y = _y;
}
public int X
{
get { return x; }
set { x = value; }
}
public int Y
{
get { return y; }
set { y = value; }
}
}
public partial class UserControl1 : UserControl
{
private List<System.Drawing.Point> points;
private List<System.Drawing.PointF> pointfs;
private List<MyPoint> mypoints;
public List<System.Drawing.Point> PointList
{
get{ return points;}
set{ points = value;}
}
public List<System.Drawing.PointF> PointFList
{
get {return pointfs;}
set{pointfs = value;}
}
public List<MyPoint> MyPointList
{
get { return mypoints; }
set { mypoints = value; }
}
public UserControl1()
{
InitializeComponent();
}
}
}
감사합니다. bde. TypeConverter.GetCreateInstanceSupported()를 true로 설정하면됩니다. – smwikipedia
true를 반환하는 GetCreateInstance()는 실제로 유형이 변경되지 않는다는 것을 의미합니다. 또는 적어도 하나의 속성이 읽기 전용이므로 즉, 속성을 수정하려는 경우 새 인스턴스를 만들어야합니다. 불행히도 이것은 항상 피할 수 없다는 것을 의미합니다. – kicsit