| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 | using System;using System.Collections.Generic;using System.Drawing;using System.Drawing.Drawing2D;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace Metis.AutoAnalysis{    internal class MeasureRangeControl : UserControl    {        float _scal;        float w;        float h;        private SampleStageModel _setting;        private float offxGrid;        private float offxC;        private float offyGrid;        private float offyC;        float _dia => _setting.Diameter;        private float _width => _setting.Width;        private float _height => _setting.Height;        //added by songxk begin        public enum MovingMethodEnum        {            Hor_Plus = 1,            Hor_Minus = 2,            Ver_Plus = 3,            Ver_Minus = 4        };        public MovingMethodEnum MovingMothed { get; set; }        public float MeasureHeight { get; set; }        public event EventHandler ChangeEvent;        //added by songxk end        public MeasureRangeControl()        {            Paint += MeasureRangeControl_Paint;        }        public void InitGrid(SampleStageModel stageSettingNow)        {            _setting = stageSettingNow;            _scal = Math.Min(Parent.Width / _width, Parent.Height / _height);            _scal = Math.Min(Parent.Height / _dia, _scal);            offxGrid = 0;            offxC = 0;            offyGrid = 0;            offyC = 0;            if (_dia > _width)            {                offxGrid = (float)((_dia - _width) * _scal) / 2;            }            else            {                offxC = (float)((_width - _dia) * _scal) / 2;            }            if (_dia > _height)            {                offyGrid = (float)((_dia - _height) * _scal) / 2;            }            else            {                offyC = (float)((_height - _dia) * _scal) / 2;            }            Invalidate();        }        public  void Reset()        {            _setting = null;            Invalidate();        }        private void MeasureRangeControl_Paint(object sender, PaintEventArgs e)        {            if (_setting == null) return;            var pen = new Pen(Color.Red);            pen.Width = 2;            pen.DashStyle = DashStyle.Dash;            var bursh = new SolidBrush(Color.White);            var g = e.Graphics;            g.FillEllipse(bursh, offxC, offyC, _dia * _scal, _dia * _scal);            g.DrawRectangle(pen, offxGrid, offyGrid, _width * _scal, _height * _scal);        }        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)        {            switch (keyData)            {                case Keys.Left:                    MovingMothed = MovingMethodEnum.Hor_Minus;                    ChangeEvent(this, new EventArgs());                    break;                case Keys.Up:                    MovingMothed = MovingMethodEnum.Ver_Plus;                    ChangeEvent(this, new EventArgs());                    break;                case Keys.Right:                    MovingMothed = MovingMethodEnum.Hor_Plus;                    ChangeEvent(this, new EventArgs());                    break;                case Keys.Down:                    MovingMothed = MovingMethodEnum.Ver_Minus;                    ChangeEvent(this, new EventArgs());                    break;                default:                    break;            }            return base.ProcessCmdKey(ref msg, keyData);        }    }}
 |