Пример #1
0
        private void ChoosePoint_handler(CustomLine line, Point point)
        {
            if (line.IsSelected())
            {
                line.IsPressed_Point_1 = false;
                line.IsPressed_Point_2 = false;

                if (line.IsNearToPoint1(point))
                {
                    line.IsPressed_Point_1 = true;
                }
                else if (line.IsNearToPoint2(point))
                {
                    line.IsPressed_Point_2 = true;
                }

                lastMousePosition = point;
            }
        }
Пример #2
0
        private void AddEventsOnLine(CustomLine line)
        {
            line.MouseLeftButtonDown += delegate(object s, MouseButtonEventArgs ea)
            {
                var point = ea.GetPosition(Canvas);
                point.Offset(-CordCenter.X, -CordCenter.Y);

                if (line.GetParent() == null)
                {
                    ChoosePoint_handler(line, point);
                }
                SelectLine_Handler(line, ea);
            };

            line.MouseLeftButtonUp += delegate(object s, MouseButtonEventArgs ea)
            {
                line.IsPressed_Point_1 = false;
                line.IsPressed_Point_2 = false;
            };

            line.PreviewMouseRightButtonDown += delegate(object s, MouseButtonEventArgs ea)
            {
                var point = ea.GetPosition(Canvas);
                point.Offset(-CordCenter.X, -CordCenter.Y);
                if (line.GetParent() == null)
                {
                    ChoosePoint_handler(line, point);
                }
                SetPointsInfo(point, line);
            };

            line.PreviewMouseRightButtonUp += delegate(object s, MouseButtonEventArgs ea)
            {
                var point = ea.GetPosition(Canvas);
                point.Offset(CordCenter.X, CordCenter.Y);
            };

            line.MouseEnter += delegate(object s, MouseEventArgs ea)
            {
                if (line.IsSelected())
                {
                    Cursor = Cursors.Hand;
                }
                //line.IsNotEntered = true;
                //if (ea.LeftButton == MouseButtonState.Pressed && !(line.IsPressed_Point_1 || line.IsPressed_Point_2))
                //{
                //    line.IsNotEntered = false;
                //}
            };
            line.MouseMove += delegate(object s, MouseEventArgs ea)
            {
                if (ea.LeftButton != MouseButtonState.Pressed)
                {
                    line.IsPressed_Point_1 = false;
                    line.IsPressed_Point_2 = false;
                }

                onLine = line;
                SetPointsInfo(ea.GetPosition(Canvas), line);
                var position = ea.GetPosition(Canvas);
                position.Offset(-CordCenter.X, -CordCenter.Y);
                if (line.IsSelected())
                {
                    if (line.IsNearToPoint1(position) || line.IsNearToPoint2(position))
                    {
                        Cursor = Cursors.SizeAll;
                    }
                    else
                    {
                        Cursor = Cursors.Hand;
                    }
                }
            };
            line.MouseLeave += delegate(object s, MouseEventArgs ea)
            {
                onLine = null;
                Cursor = Cursors.Arrow;
            };
            line.MouseUp += delegate(object s, MouseButtonEventArgs ea)
            {
                Cursor = Cursors.Arrow;
            };
        }