Connection_Point.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows.Controls;
  7. using System.Windows.Media.Effects;
  8. using System.Windows.Media;
  9. using System.Windows.Shapes;
  10. using System.Windows;
  11. namespace FlowChartModule.绘制模块
  12. {
  13. public class Connection_Point
  14. {
  15. Canvas _canvas;
  16. public Point _point;
  17. public static bool _isMouseDown=false;
  18. public bool isMouseDown=false;
  19. public List<Connection_Line> _connection_Lines ;
  20. public Ellipse ellipse = new Ellipse();
  21. public Connection_Point(Point point, Canvas canvas, List<Connection_Line> connection_Lines)
  22. {
  23. _connection_Lines = connection_Lines;
  24. _canvas=canvas;
  25. // 创建一个 Ellipse 元素
  26. ellipse.Width = 12;
  27. ellipse.Height = 12;
  28. ellipse.Fill = Brushes.Transparent;
  29. ellipse.StrokeThickness = 2;
  30. ellipse.Stroke= Brushes.Transparent;
  31. ellipse.MouseLeftButtonDown += Ellipse_MouseLeftButtonDown;
  32. ellipse.MouseLeftButtonUp += Ellipse_MouseLeftButtonUp;
  33. ellipse.MouseEnter += Ellipse_MouseEnter;
  34. ellipse.MouseLeave += Ellipse_MouseLeave;
  35. // 设置 Ellipse 元素在 Canvas 中的位置
  36. Canvas.SetLeft(ellipse, point.X);
  37. Canvas.SetTop(ellipse, point.Y);
  38. // 将 Ellipse 元素添加到 Canvas 中
  39. canvas.Children.Add(ellipse);
  40. }
  41. private void Ellipse_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
  42. {
  43. _canvas.Children.Remove(ellipse);
  44. ellipse.Stroke = Brushes.Transparent;
  45. _canvas.Children.Add(ellipse);
  46. }
  47. private void Ellipse_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
  48. {
  49. _canvas.Children.Remove(ellipse);
  50. ellipse.Fill = Brushes.Green;
  51. ellipse.Stroke = Brushes.White;
  52. _canvas.Children.Add(ellipse);
  53. }
  54. private void Ellipse_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
  55. {
  56. isMouseDown = false;
  57. // ((Ellipse) sender).ReleaseMouseCapture();
  58. }
  59. private void Ellipse_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
  60. {
  61. _isMouseDown = true;
  62. isMouseDown = true;
  63. //( ( Ellipse ) sender ).CaptureMouse();
  64. }
  65. }
  66. }