12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.Windows.Forms;
- namespace OTSMeasureApp._4_OTSSamplespaceGraphicsPanel
- {
- public class CVisualFieldGDIObject : CDisplayGDIObject
- {
- private int m_sequenceNum;
- private bool m_enable;
- public CVisualFieldGDIObject(RectangleF rectField, int OTSx, int OTSy, string name, string sampleName, Color selColor)
- {
- m_OrigineRegionF = rectField;
- SetInitRegionF(m_OrigineRegionF);
- HoleNo = name;
- SelColor = selColor;
- SampleName = sampleName;
- ID = System.Guid.NewGuid().ToString();
- OTSX = OTSx;
- OTSY = OTSy;
- }
- public int SequenceNum { get => m_sequenceNum; set => m_sequenceNum = value; }
- public bool Enable { get => m_enable; set => m_enable = value; }
- public override void OnPaint(PaintEventArgs e)
- {
- Color myColor = SelColor;
- System.Drawing.SolidBrush sampleBrush = new System.Drawing.SolidBrush(myColor);
- Pen pen;
- if (m_enable)
- {
- pen = new Pen(sampleBrush, 0.01f);
- }
- else
- {
- sampleBrush = new System.Drawing.SolidBrush(Color.Gray);
- pen = new Pen(new SolidBrush(Color.Gray), 0.01f);
- }
- e.Graphics.SmoothingMode = SmoothingMode.Default;
- //设置直线位置与尺寸
- PointF startPointF = new PointF(m_RegionF.Left, m_RegionF.Top);
- PointF endPointF = new PointF(m_RegionF.Right, m_RegionF.Bottom);
- if (m_RegionF.Height > 20)//won't display when it's too small,to speed up
- {
- float fontSize = m_RegionF.Width / 4;
- Font font;
- if (fontSize == 0)
- {
- font = new Font("宋体", 5, FontStyle.Regular);
- }
- else
- {
- font = new Font("宋体", fontSize, FontStyle.Regular);
- }
- StringFormat sf = new StringFormat();
- sf.Alignment = StringAlignment.Center;
- sf.LineAlignment = StringAlignment.Center;
- e.Graphics.DrawString(m_sequenceNum.ToString(), font, sampleBrush, m_RegionF, sf);
- }
- //绘制帧图
- e.Graphics.DrawRectangle(pen, startPointF.X, startPointF.Y, endPointF.X - startPointF.X, endPointF.Y - startPointF.Y);
- }
- }
- }
|