我想将一个对象设置为属性网格项,并带有一个弹出表单的按钮。没有按预期工作

发布于 2024-10-14 10:45:44 字数 2542 浏览 5 评论 0原文

所以我有一个属性网格,我想要绑定一个对象。当应用程序运行时,将出现一个按钮并显示一个表单,该表单将允许该对象设置其属性并返回到调用该表单的属性。

到目前为止,这是我所拥有的:

我无法让该属性显示在我的属性网格中。基本上我想使用一个表单来填写属性网格中的其他项目。

我希望我的问题足够清楚......

   public class OptoSetupFormEditor : UITypeEditor
{
    public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
    {
        return UITypeEditorEditStyle.Modal;
    }


    public override object EditValue(ITypeDescriptorContext context, System.IServiceProvider provider, object value)
    {
        IWindowsFormsEditorService svc = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
        DataTemp opto = value as DataTemp;
        if (svc != null && opto != null)
        {
            using (OptoSigmaSetup form = new OptoSigmaSetup())
            {

                if (svc.ShowDialog(form) == DialogResult.OK)
                {
                    opto.Direction = form.Direction;
                    opto.FunctionToCall = form.FunctionToCall;
                    opto.Duration = form.Duration;
                 //   OptoSigmaTest.Command = form.
                }
            }
        }
        return opto; // can also replace the wrapper object here
    }
}

  [Editor(typeof(OptoSetupFormEditor),typeof(UITypeEditor))]
    [TypeConverter(typeof(ExpandableObjectConverter))]
    public DataTemp Test1
    {
       set
       { 
           this.Duration  = value.Duration ;
           this.Direction = value.Direction; 
           this.FunctionUsed = value.FunctionToCall;
       }
    }


    [ReadOnly(true), Category("Setup")]
    public string FunctionUsed
    {
        get { return functionUsed; }
        set { functionUsed = value; }
    }


    [ReadOnly(true), Category("Setup")]
    public int Duration
    {
        get { return duration; }
        set { duration = value; }
    }

    [ReadOnly(true),Category("Setup")]
    public string Direction
    {
        get { return direction; }
        set { direction = value; }
    }

  public class DataTemp
{
    private int duration = 0;
    private string direction = "Positive";
    private string functionToCall = "Home";

    public string FunctionToCall
    {
        get { return functionToCall; }
        set { functionToCall = value; }
    }

    public int Duration
    {
        get { return duration; }
        set { duration = value; }
    }
    public string Direction
    {
        get { return direction; }
        set { direction = value; }
    }
}

提前致谢。如果需要更多说明,请告诉我

So I have a property grid that I want to have an object bound to. When the application is running a button will show up and display a form which will allow that object to have its properties set and returned back to the property that called the form.

Here is what I have so far:

I cant get the property to show up in my property grid. Basically I want to use a form to fill in other items in the property grid.

I hope my question was clear enough...

   public class OptoSetupFormEditor : UITypeEditor
{
    public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
    {
        return UITypeEditorEditStyle.Modal;
    }


    public override object EditValue(ITypeDescriptorContext context, System.IServiceProvider provider, object value)
    {
        IWindowsFormsEditorService svc = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
        DataTemp opto = value as DataTemp;
        if (svc != null && opto != null)
        {
            using (OptoSigmaSetup form = new OptoSigmaSetup())
            {

                if (svc.ShowDialog(form) == DialogResult.OK)
                {
                    opto.Direction = form.Direction;
                    opto.FunctionToCall = form.FunctionToCall;
                    opto.Duration = form.Duration;
                 //   OptoSigmaTest.Command = form.
                }
            }
        }
        return opto; // can also replace the wrapper object here
    }
}

  [Editor(typeof(OptoSetupFormEditor),typeof(UITypeEditor))]
    [TypeConverter(typeof(ExpandableObjectConverter))]
    public DataTemp Test1
    {
       set
       { 
           this.Duration  = value.Duration ;
           this.Direction = value.Direction; 
           this.FunctionUsed = value.FunctionToCall;
       }
    }


    [ReadOnly(true), Category("Setup")]
    public string FunctionUsed
    {
        get { return functionUsed; }
        set { functionUsed = value; }
    }


    [ReadOnly(true), Category("Setup")]
    public int Duration
    {
        get { return duration; }
        set { duration = value; }
    }

    [ReadOnly(true),Category("Setup")]
    public string Direction
    {
        get { return direction; }
        set { direction = value; }
    }

  public class DataTemp
{
    private int duration = 0;
    private string direction = "Positive";
    private string functionToCall = "Home";

    public string FunctionToCall
    {
        get { return functionToCall; }
        set { functionToCall = value; }
    }

    public int Duration
    {
        get { return duration; }
        set { duration = value; }
    }
    public string Direction
    {
        get { return direction; }
        set { direction = value; }
    }
}

Thanks in advance. If it needs more clarification, please let me know

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

他是夢罘是命 2024-10-21 10:45:44

您是否尝试过使用 Browsable 属性来增强您希望显示的属性?

[Browsable(true)]
[ReadOnly(true), Category("Setup")]
public string FunctionUsed
{
    get { return functionUsed; }
    set { functionUsed = value; }
}

编辑:

嗯,根据MSDN 没有此属性的属性,或者具有指定值为 true 的属性的属性,应显示在 Property 窗口中;所以这是一个尚待完善的建议。

Have you tried augmenting the properties you wish to display with the Browsable attribute?

[Browsable(true)]
[ReadOnly(true), Category("Setup")]
public string FunctionUsed
{
    get { return functionUsed; }
    set { functionUsed = value; }
}

MSDN: BrowsableAttribute

EDIT:

Hm, according to MSDN, properties without this attribute, or those which have the attribute specified with a value of true, should display in Property windows; so this is a suggestion left wanting.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文