microsoft/winforms-designer-extensibility

How to extract the parent form by ITypeDescriptorContext in Custom Type Editor EditValue method implementation?

PanchRajMaurya opened this issue · 0 comments

I have implemented a custom Type editor that inherits from UITypeEditor in .Net Framework 4.8(In Process). This type editor is intended to be used to edit properties of type FinderConfig at design time using a custom modal dialog named FinderConfiguration.
In this implementation, the context.Instance property provides access to the instance of the control that owns the property being edited. In this case, the control must implement the IXpertControlBase interface. Then I get the associated form of the control by using FindForm method and then it is passed as parameter of Editor Dialog form.
How to implement above in Out-Of-Process WinForms Designer scenario?
The source code of the editor is as below.
public class FinderConfigurationEditor : UITypeEditor
{
public override object EditValue(ITypeDescriptorContext context,
IServiceProvider provider, object value)
{
try
{
IXpertControlBase finderField = ((IXpertControlBase)context.Instance);

            FinderConfiguration frm = new FinderConfiguration(((IXpertEntryControlBase)finderField).XpertBindingSource, DomainLayerData.DomainAssemblies, (Control)finderField, ((Control)finderField).Name, ((IXpertEntryControlBase)finderField).Field_Name, (IXpertBaseForm)((Control)finderField).FindForm());
            frm._obj = (FinderConfig)value;
            frm.ShowDialog();
            if (frm.DialogResult == DialogResult.OK)
                value = frm._obj;

        }
        catch (Exception ex)
        {
            clsCommon.MyMessageBoxShow(ex.Message);
            return base.EditValue(context, provider, value);
        }
        return base.EditValue(context, provider, value);
    }
    public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
    {
        return UITypeEditorEditStyle.Modal;
    }
}