さて、私はついにこれを達成する方法を突き止めることができました.
CollectionEditor.CollectionForm
必要に近いカスタムを作成しようとしましたが、それは正しい方向ではありませんでした。
まず、コレクションを編集するための GUI を含む通常の Windows フォームを作成します。次に、DialogResult を返すボタンをフォームに含めるだけです。
今、私が探していたものを達成するための鍵は、CollectionEditor.CollectionForm
私が思っていた正しいアプローチではなく、UITypeEditor
.
そこで、UITypeEditor を継承したクラスを作成しました。次に、次のように肉付けするだけです。
public class CustomCollectionModalEditor: UITypeEditor
{
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
if (context ==null || context.Instance == null)
return base.GetEditStyle(context);
return UITypeEditorEditStyle.Modal;
}
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
{
IWindowsFormsEditorService editorService;
if (context == null || context.Instance == null || provider == null)
return value;
editorService = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
CForm CollectionEditor = new CForm();
if (editorService.ShowDialog(CollectionEditor) == System.Windows.Forms.DialogResult.OK)
return CollectionEditor.Programmed;
return value;
//return base.EditValue(context, provider, value);
}
}
注意すべき重要な部分は、関数GetEditStyle
とEditValue
です。コレクションを編集するために作成したフォームを起動する部分は、EditValue
オーバーライド関数にあります。
CForm
コレクションを編集するために、このテストで設計したカスタム コレクション エディター フォームです。コレクションを編集するために設計したフォームを表示するには、 にIWindowsFormsEditorService
関連付けられているを取得し、のIServiceProvider
を呼び出すだけです。次に、フォームから返された値を取得し、必要なカスタム処理を実行できます。.ShowDialog(formVariable)
IWindowsFormsEditorService
catch
DialogResult
これを組み込む正しい方法を決定するためにかなりの掘り下げが必要だったので、これが誰かの助けになることを願っています.