frmInitializeTwoPointRectangle.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  1. using OTSMeasureApp._0_OTSModel.OTSDataType;
  2. using OTSModelSharp.ServiceCenter;
  3. using System;
  4. using System.Collections;
  5. using System.Drawing;
  6. using System.Drawing.Drawing2D;
  7. using System.Windows.Forms;
  8. namespace OTSMeasureApp._4_OTSSamplespaceGraphicsPanel
  9. {
  10. public partial class frmInitializeTwoPointRectangle : Form
  11. {
  12. ISemController cfun;
  13. public PointF LTPoint;
  14. public PointF RBPoint;
  15. public PointF TheThirdPoint;
  16. public bool IsInclinedPlaneFocus = false;
  17. OTSCommon.Language lan;
  18. Hashtable table;
  19. CSlopFocusParam slopFocusParam;
  20. public frmInitializeTwoPointRectangle()
  21. {
  22. InitializeComponent();
  23. lan = new OTSCommon.Language(this);
  24. table = lan.GetNameTable(this.Name);
  25. if (panel1 != null)
  26. {
  27. panel1.Paint += Panel1_Paint;
  28. panel1.MouseMove += Panel1_MouseMove;
  29. panel1.MouseLeave += Panel1_MouseLeave;
  30. panel1.Resize += Panel1_Resize;
  31. }
  32. }
  33. private void bn_FirstPoint_Click(object sender, EventArgs e)
  34. {
  35. double Px = 0;
  36. double Py = 0;
  37. double Pr = 0;
  38. if (cfun.GetSemPositionXY(ref Px, ref Py, ref Pr))
  39. {
  40. tB_LTPointX.Text = Math.Round(Px,2).ToString();
  41. tB_LTPointY.Text = Math.Round(Py, 2).ToString();
  42. }
  43. double WD = 0;
  44. if (cfun.GetWorkingDistance(ref WD))
  45. {
  46. tB_LTPointWD.Text = WD.ToString();
  47. }
  48. if (panel1 != null) panel1.Invalidate();
  49. }
  50. private void bn_SecondPoint_Click(object sender, EventArgs e)
  51. {
  52. double Px = 0;
  53. double Py = 0;
  54. double Pr = 0;
  55. if (cfun.GetSemPositionXY(ref Px, ref Py, ref Pr))
  56. {
  57. tB_RBPointX.Text = Math.Round(Px,2).ToString();
  58. tB_RBPointY.Text = Math.Round(Py, 2).ToString();
  59. }
  60. double WD = 0;
  61. if (cfun.GetWorkingDistance(ref WD))
  62. {
  63. tBx_RBPointWD.Text = WD.ToString();
  64. }
  65. if (panel1 != null) panel1.Invalidate();
  66. }
  67. private void frmInitializeTwoPointRectangle_Load(object sender, EventArgs e)
  68. {
  69. if (cfun == null){cfun = SemController.GetSEMController();}
  70. cB_Inclinedplanefocus.Checked=true;double val=0;
  71. if(cfun.GetMagnification(ref val)) tBx_Magnification.Text=val.ToString();
  72. InitializeDrawingAreas();
  73. panel1.Invalidate();
  74. }
  75. private void button1_Click(object sender, EventArgs e)
  76. {
  77. if (tB_LTPointWD.Text == "")
  78. {
  79. MessageBox.Show("Please read first!");
  80. return;
  81. }
  82. double Px = Convert.ToDouble(tB_LTPointX.Text);
  83. double Py = Convert.ToDouble(tB_LTPointY.Text);
  84. double wd = Convert.ToDouble(tB_LTPointWD.Text);
  85. if (cfun.MoveSEMToPoint(Px, Py)) cfun.SetWorkingDistance(wd);
  86. }
  87. private void button2_Click(object sender, EventArgs e)
  88. {
  89. if (tBx_RBPointWD.Text == "")
  90. {
  91. MessageBox.Show("Please read first!");
  92. return;
  93. }
  94. double Px = Convert.ToDouble(tB_RBPointX.Text);
  95. double Py = Convert.ToDouble(tB_RBPointY.Text);
  96. double wd = Convert.ToDouble(tBx_RBPointWD.Text);
  97. if (cfun.MoveSEMToPoint(Px, Py))
  98. {
  99. cfun.SetWorkingDistance(wd);
  100. }
  101. }
  102. private void bn_TheThirdPoint_Click(object sender, EventArgs e)
  103. {
  104. double Px = 0;
  105. double Py = 0;
  106. double Pr = 0;
  107. if (cfun.GetSemPositionXY(ref Px, ref Py, ref Pr))
  108. {
  109. tBx_TheThirdPointX.Text = Math.Round(Px,2).ToString();
  110. tBx_TheThirdPointY.Text = Math.Round(Py,2).ToString();
  111. }
  112. double WD = 0;
  113. if (cfun.GetWorkingDistance(ref WD))
  114. {
  115. tBx_TheThirdPointWD.Text = WD.ToString();
  116. }
  117. if (panel1 != null) panel1.Invalidate();
  118. }
  119. private void btn_gtTheThirdPoint_Click(object sender, EventArgs e)
  120. {
  121. if (tBx_TheThirdPointWD.Text == "")
  122. {
  123. MessageBox.Show("Please read first!");
  124. return;
  125. }
  126. double Px = Convert.ToDouble(tBx_TheThirdPointX.Text);
  127. double Py = Convert.ToDouble(tBx_TheThirdPointY.Text);
  128. double wd = Convert.ToDouble(tBx_TheThirdPointWD.Text);
  129. if (cfun.MoveSEMToPoint(Px, Py))
  130. {
  131. cfun.SetWorkingDistance(wd);
  132. }
  133. }
  134. private void bn_OK_Click(object sender, EventArgs e)
  135. {
  136. double iPX1, iPY1, iPX2, iPY2, iPX3, iPY3;
  137. iPX1 = iPY1 = iPX2 = iPY2 = iPX3 = iPY3 = 0;
  138. double dPW1, dPW2, dPW3;
  139. dPW1 = dPW2 = dPW3 = 0;
  140. if (!double.TryParse(tB_LTPointX.Text, out iPX1) || !double.TryParse(tB_LTPointY.Text, out iPY1) || !double.TryParse(tB_RBPointX.Text, out iPX2) || !double.TryParse(tB_RBPointY.Text, out iPY2) || !double.TryParse(tB_LTPointWD.Text, out dPW1) || !double.TryParse(tBx_RBPointWD.Text, out dPW2) )
  141. {
  142. DialogResult result= MessageBox.Show("Please check Params!");
  143. this.DialogResult= DialogResult.None;
  144. return;
  145. }
  146. if (tB_LTPointX.Text == tB_RBPointX.Text && tB_LTPointY.Text == tB_RBPointY.Text)
  147. {
  148. DialogResult result= MessageBox.Show("Please select different points!");
  149. this.DialogResult = DialogResult.None;
  150. return;
  151. }
  152. if(cB_Inclinedplanefocus.Checked)
  153. {
  154. if(!double.TryParse(tBx_TheThirdPointX.Text, out iPX3) || !double.TryParse(tBx_TheThirdPointY.Text, out iPY3) || !double.TryParse(tBx_TheThirdPointWD.Text, out dPW3))
  155. {
  156. MessageBox.Show("Please check Params!");
  157. this.DialogResult = DialogResult.None;
  158. return;
  159. }
  160. if((tB_LTPointX.Text == tBx_TheThirdPointX.Text && tB_LTPointX.Text ==tBx_TheThirdPointY.Text) || (tB_LTPointX.Text == tBx_TheThirdPointY.Text && tB_RBPointY.Text == tBx_TheThirdPointY.Text))
  161. {
  162. MessageBox.Show("Please check Params!");
  163. this.DialogResult = DialogResult.None;
  164. return;
  165. }
  166. }
  167. LTPoint = new PointF((float)iPX1, (float)iPY1);
  168. RBPoint = new PointF((float)iPX2, (float)iPY2);
  169. TheThirdPoint = new PointF((float)iPX3, (float)iPY3);
  170. if (slopFocusParam == null)
  171. {
  172. slopFocusParam = new CSlopFocusParam();
  173. }
  174. slopFocusParam.IsUsingSlopParam = cB_Inclinedplanefocus.Checked;
  175. slopFocusParam.FirstPoint = new Point((int)iPX1, (int)iPY1);
  176. slopFocusParam.FirstWD = dPW1;
  177. slopFocusParam.SecondPoint = new Point((int)iPX2, (int)iPY2);
  178. slopFocusParam.SecondWD = dPW2;
  179. slopFocusParam.ThirdPoint = new Point((int)iPX3, (int)iPY3);
  180. slopFocusParam.ThirdWD = dPW3;
  181. this.Close();
  182. }
  183. private void bn_Cancel_Click(object sender, EventArgs e)
  184. {
  185. this.Close();
  186. }
  187. private void cB_Inclinedplanefocus_CheckedChanged(object sender, EventArgs e)
  188. {
  189. if (cB_Inclinedplanefocus.Checked)
  190. {
  191. IsInclinedPlaneFocus = true;
  192. groupBox3.Enabled =true;
  193. foreach (Control c in groupBox3.Controls)
  194. {
  195. c.Enabled = true;
  196. }
  197. }
  198. else
  199. {
  200. IsInclinedPlaneFocus = false;
  201. isMouseInThirdPoint = false;
  202. UpdateGroupBoxHighlight(groupBox3, false); // 需要确认存在groupBox3控件
  203. groupBox3.Enabled =false;
  204. foreach (Control c in groupBox3.Controls)
  205. {
  206. c.Enabled = false;
  207. }
  208. }
  209. if (panel1 != null)
  210. {
  211. panel1.Invalidate();
  212. }
  213. }
  214. public CSlopFocusParam GetCSlopFocusParam()
  215. {
  216. return slopFocusParam;
  217. }
  218. public double GetMagnification()
  219. {
  220. double dMagnification = 0;
  221. double.TryParse(tBx_Magnification.Text, out dMagnification);
  222. return dMagnification;
  223. }
  224. private RectangleF rectangleArea;
  225. private RectangleF topLeftCircle;
  226. private RectangleF bottomRightCircle;
  227. private RectangleF thirdPointCircle;
  228. private bool isMouseInTopLeft = false;
  229. private bool isMouseInBottomRight = false;
  230. private bool isMouseInThirdPoint = false;
  231. private void Panel1_Resize(object sender, EventArgs e)
  232. {
  233. InitializeDrawingAreas();
  234. panel1.Invalidate();
  235. }
  236. // 初始化绘图区域
  237. private void InitializeDrawingAreas()
  238. {
  239. if (panel1 == null) return;
  240. // 定义矩形区域(居中显示)
  241. int margin = 30;
  242. rectangleArea = new RectangleF(
  243. margin,
  244. margin,
  245. panel1.Width - 2 * margin,
  246. panel1.Height - 2 * margin);
  247. // 定义圆圈区域(直径16像素)
  248. float circleDiameter = 16f;
  249. float circleRadius = circleDiameter / 2;
  250. topLeftCircle = new RectangleF(
  251. rectangleArea.Left - circleRadius,
  252. rectangleArea.Top - circleRadius,
  253. circleDiameter, circleDiameter);
  254. bottomRightCircle = new RectangleF(
  255. rectangleArea.Right - circleRadius,
  256. rectangleArea.Bottom - circleRadius,
  257. circleDiameter, circleDiameter);
  258. // 第三个点位于矩形内部,靠近右边但不在对角线上
  259. thirdPointCircle = new RectangleF(
  260. rectangleArea.Right - circleRadius - 30,
  261. rectangleArea.Top + rectangleArea.Height / 3 - circleRadius,
  262. circleDiameter, circleDiameter);
  263. }
  264. // Panel 绘制事件 - 创建高级视觉效果
  265. private void Panel1_Paint(object sender, PaintEventArgs e)
  266. {
  267. Graphics g = e.Graphics;
  268. g.SmoothingMode = SmoothingMode.AntiAlias;
  269. g.CompositingQuality = CompositingQuality.HighQuality;
  270. // 确保绘图区域已初始化
  271. if (rectangleArea.IsEmpty)
  272. {
  273. InitializeDrawingAreas();
  274. }
  275. // 绘制高级效果矩形(绿色背景)
  276. DrawAdvancedRectangle(g, rectangleArea);
  277. // 绘制带渐变的圆圈(黄色)
  278. DrawAdvancedCircle(g, topLeftCircle, isMouseInTopLeft);
  279. DrawAdvancedCircle(g, bottomRightCircle, isMouseInBottomRight);
  280. // 如果选中了倾斜平面焦点选项,绘制第三个点
  281. if (cB_Inclinedplanefocus.Checked)
  282. {
  283. DrawAdvancedCircle(g, thirdPointCircle, isMouseInThirdPoint);
  284. // 在第三个点上方绘制"任意非对角线点"文字
  285. DrawNonDiagonalPointLabel(g, thirdPointCircle);
  286. // 显示第三个点坐标
  287. if (tBx_TheThirdPointX.Text != "" && tBx_TheThirdPointY.Text != "")
  288. {
  289. DrawPointCoordinates(g, thirdPointCircle, tBx_TheThirdPointX.Text, tBx_TheThirdPointY.Text, "THIRD");
  290. }
  291. }
  292. // 显示左上角点坐标
  293. if (tB_LTPointX.Text != "" && tB_LTPointY.Text != "")
  294. {
  295. DrawPointCoordinates(g, topLeftCircle, tB_LTPointX.Text, tB_LTPointY.Text, "LT");
  296. }
  297. // 显示右下角点坐标
  298. if (tB_RBPointX.Text != "" && tB_RBPointY.Text != "")
  299. {
  300. DrawPointCoordinates(g, bottomRightCircle, tB_RBPointX.Text, tB_RBPointY.Text, "RB");
  301. }
  302. }
  303. // 绘制坐标值
  304. private void DrawPointCoordinates(Graphics g, RectangleF circleRect, string xValue, string yValue, string Pointlocation)
  305. {
  306. string coordinates = $"({xValue}, {yValue})";
  307. // 使用高质量文本渲染
  308. g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
  309. // 定义字体
  310. using (Font font = new Font("微软雅黑", 8, FontStyle.Regular))
  311. {
  312. // 测量文字大小
  313. SizeF textSize = g.MeasureString(coordinates, font);
  314. float textX, textY;
  315. if (Pointlocation == "LT")
  316. {
  317. // 左上角点:坐标显示在右下方
  318. textX = circleRect.Right + 5;
  319. textY = circleRect.Bottom + 5;
  320. }
  321. else if (Pointlocation == "RB")
  322. {
  323. // 右下角点:坐标显示在左上方
  324. textX = circleRect.Left - textSize.Width - 5;
  325. textY = circleRect.Top - textSize.Height - 5;
  326. }
  327. else
  328. {
  329. // 对于其他点(包括第三个点):坐标显示在下方
  330. textX = circleRect.X + (circleRect.Width - textSize.Width) / 2; // 居中
  331. textY = circleRect.Bottom + 5; // 下方5像素
  332. }
  333. // 确保文字不会超出边界
  334. if (textX < 0) textX = 0;
  335. if (textY < 0) textY = 0;
  336. if (textX + textSize.Width > panel1.Width) textX = panel1.Width - textSize.Width;
  337. if (textY + textSize.Height > panel1.Height) textY = panel1.Height - textSize.Height;
  338. // 绘制坐标文字(银白色)
  339. using (SolidBrush textBrush = new SolidBrush(Color.White))
  340. {
  341. g.DrawString(coordinates, font, textBrush, textX, textY);
  342. }
  343. }
  344. }
  345. // 绘制"任意非对角线点"文字标识
  346. private void DrawNonDiagonalPointLabel(Graphics g, RectangleF circleRect)
  347. {
  348. string labelText = "任意非对角线点";
  349. // 使用高质量文本渲染
  350. g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
  351. // 定义字体
  352. using (Font font = new Font("微软雅黑", 9, FontStyle.Bold))
  353. {
  354. // 测量文字大小
  355. SizeF textSize = g.MeasureString(labelText, font);
  356. // 计算文字位置(在圆圈上方居中)
  357. float textX = circleRect.X + (circleRect.Width - textSize.Width) / 2;
  358. float textY = circleRect.Y - textSize.Height - 5; // 上方5像素间距
  359. // 创建文字路径以实现轮廓效果
  360. using (GraphicsPath textPath = new GraphicsPath())
  361. {
  362. textPath.AddString(
  363. labelText,
  364. FontFamily.GenericSansSerif,
  365. (int)FontStyle.Bold,
  366. g.DpiY * 9 / 72, // 9pt 转换为像素
  367. new PointF(textX, textY),
  368. StringFormat.GenericDefault);
  369. // 绘制文字阴影效果
  370. using (Matrix translateMatrix = new Matrix())
  371. {
  372. translateMatrix.Translate(1, 1);
  373. textPath.Transform(translateMatrix);
  374. using (SolidBrush shadowBrush = new SolidBrush(Color.FromArgb(120, 0, 0, 0)))
  375. {
  376. g.FillPath(shadowBrush, textPath);
  377. }
  378. // 恢复原始位置
  379. translateMatrix.Reset();
  380. translateMatrix.Translate(-1, -1);
  381. textPath.Transform(translateMatrix);
  382. }
  383. // 绘制文字主体(深绿色)
  384. using (SolidBrush textBrush = new SolidBrush(Color.DarkGreen))
  385. {
  386. g.FillPath(textBrush, textPath);
  387. }
  388. // 绘制文字边框(可选)
  389. using (Pen textPen = new Pen(Color.FromArgb(180, Color.ForestGreen), 0.5f))
  390. {
  391. g.DrawPath(textPen, textPath);
  392. }
  393. }
  394. }
  395. }
  396. // 绘制高级效果矩形(绿色背景)
  397. private void DrawAdvancedRectangle(Graphics g, RectangleF rect)
  398. {
  399. // 创建圆角矩形路径
  400. using (GraphicsPath path = new GraphicsPath())
  401. {
  402. float radius = 10f;
  403. path.AddArc(rect.X, rect.Y, radius, radius, 180, 90);
  404. path.AddArc(rect.Right - radius, rect.Y, radius, radius, 270, 90);
  405. path.AddArc(rect.Right - radius, rect.Bottom - radius, radius, radius, 0, 90);
  406. path.AddArc(rect.X, rect.Bottom - radius, radius, radius, 90, 90);
  407. path.CloseFigure();
  408. // 填充绿色渐变背景
  409. using (LinearGradientBrush brush = new LinearGradientBrush(
  410. rect, Color.FromArgb(144, 238, 144), Color.FromArgb(0, 100, 0), 45f)) // 浅绿到深绿
  411. {
  412. g.FillPath(brush, path);
  413. }
  414. // 绘制外边框
  415. using (Pen pen = new Pen(Color.FromArgb(0, 100, 0), 2)) // 深绿色边框
  416. {
  417. g.DrawPath(pen, path);
  418. }
  419. // 添加内部发光效果
  420. using (Pen innerPen = new Pen(Color.FromArgb(144, 255, 144), 1)) // 浅绿色内边框
  421. {
  422. innerPen.Alignment = PenAlignment.Inset;
  423. RectangleF innerRect = new RectangleF(rect.X + 1, rect.Y + 1, rect.Width - 2, rect.Height - 2);
  424. using (GraphicsPath innerPath = new GraphicsPath())
  425. {
  426. float innerRadius = 8f;
  427. innerPath.AddArc(innerRect.X, innerRect.Y, innerRadius, innerRadius, 180, 90);
  428. innerPath.AddArc(innerRect.Right - innerRadius, innerRect.Y, innerRadius, innerRadius, 270, 90);
  429. innerPath.AddArc(innerRect.Right - innerRadius, innerRect.Bottom - innerRadius, innerRadius, innerRadius, 0, 90);
  430. innerPath.AddArc(innerRect.X, innerRect.Bottom - innerRadius, innerRadius, innerRadius, 90, 90);
  431. innerPath.CloseFigure();
  432. g.DrawPath(innerPen, innerPath);
  433. }
  434. }
  435. // 添加阴影效果
  436. using (Pen shadowPen = new Pen(Color.FromArgb(50, 0, 0, 0), 3))
  437. {
  438. shadowPen.Alignment = PenAlignment.Outset;
  439. g.DrawPath(shadowPen, path);
  440. }
  441. }
  442. }
  443. // 绘制高级效果圆圈(黄色)
  444. private void DrawAdvancedCircle(Graphics g, RectangleF circleRect, bool isHovered)
  445. {
  446. // 创建圆形路径
  447. using (GraphicsPath path = new GraphicsPath())
  448. {
  449. path.AddEllipse(circleRect);
  450. // 使用黄色系
  451. Color centerColor = isHovered ? Color.Gold : Color.Yellow; // 悬停时用金色,正常时用黄色
  452. Color rimColor = isHovered ? Color.Orange : Color.Goldenrod; // 悬停时用橙色,正常时用金麒麟色
  453. // 径向渐变画刷
  454. using (PathGradientBrush brush = new PathGradientBrush(path))
  455. {
  456. brush.CenterColor = centerColor;
  457. brush.SurroundColors = new Color[] { rimColor };
  458. brush.CenterPoint = new PointF(
  459. circleRect.X + circleRect.Width / 2,
  460. circleRect.Y + circleRect.Height / 2);
  461. // 设置焦点缩放以创建更好的渐变效果
  462. brush.FocusScales = new PointF(0.3f, 0.3f);
  463. g.FillPath(brush, path);
  464. }
  465. // 添加高光效果(左上角的小圆形高光)
  466. RectangleF highlightRect = new RectangleF(
  467. circleRect.X + circleRect.Width * 0.15f,
  468. circleRect.Y + circleRect.Height * 0.15f,
  469. circleRect.Width * 0.3f,
  470. circleRect.Height * 0.3f);
  471. using (SolidBrush highlightBrush = new SolidBrush(Color.FromArgb(200, Color.White)))
  472. {
  473. g.FillEllipse(highlightBrush, highlightRect);
  474. }
  475. // 添加边框
  476. using (Pen pen = new Pen(Color.FromArgb(200, Color.SaddleBrown), isHovered ? 2.5f : 1.5f))
  477. {
  478. g.DrawEllipse(pen, circleRect);
  479. }
  480. // 添加外发光效果
  481. if (isHovered)
  482. {
  483. using (Pen glowPen = new Pen(Color.FromArgb(100, Color.Orange), 3))
  484. {
  485. glowPen.Alignment = PenAlignment.Outset;
  486. g.DrawEllipse(glowPen, circleRect);
  487. }
  488. }
  489. }
  490. }
  491. // 鼠标移动事件处理
  492. private void Panel1_MouseMove(object sender, MouseEventArgs e)
  493. {
  494. bool wasInTopLeft = isMouseInTopLeft;
  495. bool wasInBottomRight = isMouseInBottomRight;
  496. bool wasInThirdPoint = isMouseInThirdPoint;
  497. // 检测鼠标是否在圆圈内
  498. isMouseInTopLeft = IsPointInCircle(e.Location, topLeftCircle);
  499. isMouseInBottomRight = IsPointInCircle(e.Location, bottomRightCircle);
  500. // 只有在选中倾斜平面焦点时才检查第三个点
  501. if (cB_Inclinedplanefocus.Checked)
  502. {
  503. isMouseInThirdPoint = IsPointInCircle(e.Location, thirdPointCircle);
  504. }
  505. else
  506. {
  507. isMouseInThirdPoint = false;
  508. }
  509. // 如果状态发生变化,刷新显示并更新GroupBox高亮
  510. if (wasInTopLeft != isMouseInTopLeft ||
  511. wasInBottomRight != isMouseInBottomRight ||
  512. wasInThirdPoint != isMouseInThirdPoint)
  513. {
  514. panel1.Invalidate();
  515. // 更新GroupBox高亮状态
  516. if (wasInTopLeft != isMouseInTopLeft)
  517. UpdateGroupBoxHighlight(groupBox1, isMouseInTopLeft);
  518. if (wasInBottomRight != isMouseInBottomRight)
  519. UpdateGroupBoxHighlight(groupBox2, isMouseInBottomRight);
  520. if (wasInThirdPoint != isMouseInThirdPoint)
  521. UpdateGroupBoxHighlight(groupBox3, isMouseInThirdPoint);
  522. }
  523. }
  524. // 鼠标离开Panel区域
  525. private void Panel1_MouseLeave(object sender, EventArgs e)
  526. {
  527. bool wasInTopLeft = isMouseInTopLeft;
  528. bool wasInBottomRight = isMouseInBottomRight;
  529. bool wasInThirdPoint = isMouseInThirdPoint;
  530. isMouseInTopLeft = false;
  531. isMouseInBottomRight = false;
  532. isMouseInThirdPoint = false;
  533. panel1.Invalidate();
  534. // 取消GroupBox高亮
  535. if (wasInTopLeft)
  536. UpdateGroupBoxHighlight(groupBox1, false);
  537. if (wasInBottomRight)
  538. UpdateGroupBoxHighlight(groupBox2, false);
  539. if (wasInThirdPoint)
  540. UpdateGroupBoxHighlight(groupBox3, false);
  541. }
  542. // 检查点是否在圆内
  543. private bool IsPointInCircle(Point point, RectangleF circle)
  544. {
  545. if (circle.IsEmpty) return false;
  546. float centerX = circle.X + circle.Width / 2;
  547. float centerY = circle.Y + circle.Height / 2;
  548. float radius = circle.Width / 2;
  549. float distance = (float)Math.Sqrt(
  550. Math.Pow(point.X - centerX, 2) +
  551. Math.Pow(point.Y - centerY, 2));
  552. return distance <= radius;
  553. }
  554. // 更新GroupBox高亮效果
  555. private void UpdateGroupBoxHighlight(GroupBox groupBox, bool isHighlighted)
  556. {
  557. if (groupBox == null) return;
  558. if (isHighlighted)
  559. {
  560. // 高亮效果:黄色边框和浅绿色背景
  561. groupBox.BackColor = Color.FromArgb(240, 255, 240);
  562. groupBox.ForeColor = Color.DarkGreen;
  563. }
  564. else
  565. {
  566. // 恢复默认样式
  567. groupBox.BackColor = SystemColors.Control;
  568. groupBox.ForeColor = SystemColors.ControlText;
  569. }
  570. // 强制刷新GroupBox显示
  571. groupBox.Invalidate();
  572. }
  573. }
  574. }