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; 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); } } }