1、我们经常使用propertyGrid绑定一个含有众多属性成员的类的对象,从而实现对这个类中属性参数值的设置和读取,如下图:
在这里插入图片描述
我们可以看出,这个类如下:

 public   class MotionParameter
    {
        [DisplayName("起始速度"),  Description("板卡的起始速度"), ReadOnly(false )]
        public   double StartVel { get; set; }
        [DisplayName("高速运行速度"),  Description("板卡告诉运行时的速度"), ReadOnly(false )]
        public double Vel { get; set; }
        public double Acc { get; set; }
        public double Dec { get; set; }

        public double Dis { get; set; }
        public double time { get; set; }
        public Jerk jerk { get; set; } = Jerk.S;
    }

对于以上用法,在运动控制中只能用于设置一个轴的参数,但是当一台机器有很多个轴的时候,比如四个轴,难道我们要使用四个propertyGrid控件吗?答案是否定的,我们可以有更好的方法,利用嵌套属性来实现,先看效果图,如下:
在这里插入图片描述
也就是说我们新建一个类,这个类中的属性成员的类就是之前提到的MotionParameter自定义类,而不是一直系统固有的类,代码如下:

[Serializable]
public class DeltaMotionParameter
{

    [DisplayName("轴1"), Category("轴参数设置"), Description("")]
    public MotionParameter motionParameter1
    {
        get
        {
            return Axis1Parm;
        }

        set
        {
           Axis1Parm=value ;
        }
    }
    [DisplayName("轴2"), Category("轴参数设置"), Description(""), ReadOnly(false)]

    public MotionParameter motionParameter2
    {
        get
        {
            return Axis2Parm;
        }

        set
        {
             Axis2Parm=value;
        }

    }
    [DisplayName("轴3"), Category("轴参数设置"), Description(""), ReadOnly(false)]
    public MotionParameter motionParameter3
    {
        get
        {
            return Axis3Parm;
        }

        set
        {
            Axis3Parm=value ;
        }

    }
    [DisplayName("轴4"), Category("轴参数设置"), Description(""), ReadOnly(false)]
    public MotionParameter motionParameter4
    {
        get
        {
            return Axis4Parm;
        }

        set
        {
             Axis4Parm=value ;
        }

    }

    private MotionParameter Axis1Parm = new MotionParameter();
    private MotionParameter Axis2Parm = new MotionParameter();
    private MotionParameter Axis3Parm = new MotionParameter();
    private MotionParameter Axis4Parm = new MotionParameter();
}

再结合序列化/反序列化最终可以实现参数的设置。

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐