AxisPointControl.cs 2.5 KB
using OnlineStore.Common;
using OnlineStore.DeviceLibrary;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace OnlineStore.XLRStore.useControl
{
    public partial class AxisPointControl : UserControl
    {
        public AxisPointControl()
        {
            InitializeComponent();
        }
        public string PointText
        {
            get { return btnMove.Text; }
            set { btnMove.Text = value; }
        }

        public int PointValue
        {
            get { return FormUtil.GetIntValue(txtPoint.Text); }
            set { txtPoint.Text = value.ToString(); }
        }
        public Color PointBackColor
        {
            get { return btnMove.BackColor; }
            set { this.btnMove.BackColor = value; }
        }
        public Color PointForeColor
        {
            get { return btnMove.ForeColor; }
            set { this.btnMove.ForeColor = value; }
        }
        private int MoveSpeed;
        private AxisBean MoveAxis = null;
        private bool isRelMovePoint=false;
        public void SetMoveData(AxisBean axisBean, int speed, int pointV, bool isRelMovePoint=false)
        {
            this.MoveAxis = axisBean;
            this.MoveSpeed = speed;
            this.PointValue = pointV;
            this.isRelMovePoint = isRelMovePoint;
        }
        private void btnMove_Click(object sender, EventArgs e)
        {
            int v = FormUtil.GetIntValue(txtPoint);
            if (isRelMovePoint)
            {
                if (v<=0)
                {
                    MessageBox.Show(PointText + "为相对运动,请正确设置点位", "操作失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                int currPosition = MoveAxis.GetAclPosition();
                int targetPosition = currPosition + v;
                LogUtil.info(this.Name + " " + MoveAxis.AxisName + " 点击:" + btnMove.Text + ",增量运动【" + v + "】,目标位置【"+ targetPosition + "】"); 
                MoveAxis.AbsMove(null, targetPosition, MoveSpeed);
            }
            else
            { 
                LogUtil.info(this.Name + " " + MoveAxis.AxisName + " 点击:" + btnMove.Text + ",绝对运动【" + v + "】"); 
                MoveAxis.AbsMove(null, v, MoveSpeed);
            }
        }
    }
}