既存のウィンドウフォームアプリケーションがあります。アプリケーションにはプロパティグリッドがあります。プロパティの値は、実行時にユーザーが設定します。私がやりたいのは、コードから特定のプロパティの現在の値を決定することです。私は部分的に成功しました。カテゴリと物件名情報を取得できます。ユーザーが設定したプロパティの現在の値と、他の2つの関連する質問を取得するのに問題があります。
私が使用しているコードは次のとおりです。
// ICustomTypeDescriptor Interface Implementation
public AttributeCollection GetAttributes()
{
return TypeDescriptor.GetAttributes(GetType());
}
public string GetClassName()
{
return TypeDescriptor.GetClassName(GetType());
}
public string GetComponentName()
{
return TypeDescriptor.GetComponentName(GetType());
}
public TypeConverter GetConverter()
{
return TypeDescriptor.GetConverter(GetType());
}
public EventDescriptor GetDefaultEvent()
{
return TypeDescriptor.GetDefaultEvent(GetType());
}
public PropertyDescriptor GetDefaultProperty()
{
return TypeDescriptor.GetDefaultProperty(GetType());
}
public object GetEditor(Type editorBaseType)
{
return TypeDescriptor.GetEditor(GetType(), editorBaseType);
}
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{
return TypeDescriptor.GetEvents(GetType(), attributes);
}
public EventDescriptorCollection GetEvents()
{
return TypeDescriptor.GetEvents(GetType());
}
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{
// ... This returns a list of properties.
PropertyDescriptorCollection pdc = TypeDescriptor.GetProperties(GetType(), attributes);
PropertyDescriptor[] arr = new PropertyDescriptor[pdc.Count];
pdc.CopyTo(arr, 0);
PropertyDescriptorCollection propertyCollection = new PropertyDescriptorCollection(arr);
ModifyProperties(propertyCollection); // modifies which properties are visible
// temporary code to get the program to print out the properties
foreach (PropertyDescriptor pd in propertyCollection)
{
Print("input category = "+pd.Category);
Print("input display name = "+pd.DisplayName);
Print("input name = "+pd.Name);
// Print("input value = "+pd.GetValue(Input).ToString()); <--- Does NOT work
}
return propertyCollection;
}
public PropertyDescriptorCollection GetProperties()
{
return TypeDescriptor.GetProperties(GetType());
}
public object GetPropertyOwner(PropertyDescriptor pd)
{
return this;
}
私の質問は次のとおりです。
プロパティの値を取得するにはどうすればよいですか?たとえば、プロパティのアスペクト比があります。その表示名はアスペクト比であり、その名前はアスペクト比です。その値は5です。実行時にコードを介してこれを取得するにはどうすればよいですか?
プロパティを注文するにはどうすればよいですか。上記のアプローチを使用してプロパティを注文しようとしましたが、注文に失敗しました。どうすればいいのかわかりません。
任意の提案をいただければ幸いです。ありがとうございました。