All pastes #507082 Raw Edit

Stuff

public text v1 · immutable
·published 2007-05-24 11:29 UTC
rendered paste body
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms.Design;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;

namespace WP_task8
{
    class MyDesigner : ControlDesigner
    {
        private PolygonControl component;
        private int movePoint = -1;

        public override void Initialize(IComponent component)
        {
            this.component = component as PolygonControl;
            base.Initialize(component);
        }

        protected override void OnMouseDragBegin(int x, int y)
        {
            if (PolygonControl.MouseButtons == MouseButtons.Left)
            {
                Point p = component.PointToClient(new Point(x, y));
                movePoint = component.PointByXY(p.X, p.Y);
                if (movePoint >= 0)
                {
                    component.Capture = true;
                }
            }
            if (movePoint < 0)
            {
                base.OnMouseDragBegin(x, y);
            }
        }

        protected override void OnMouseDragMove(int x, int y)
        {
            if (movePoint >= 0)
            {
                Point p = component.PointToClient(new Point(x, y));
                component.Points[movePoint].X = p.X;
                component.Points[movePoint].Y = p.Y;
                component.Invalidate();
            }
            else
            {
                base.OnMouseDragMove(x, y);
            }
        }

        protected override void OnMouseDragEnd(bool cancel)
        {
            if (movePoint >= 0)
            {
                movePoint = -1;
                component.Capture = false;
                TypeDescriptor.GetProperties(component)["Points"].SetValue(component, component.Points);
                component.Invalidate();
            }
            else
            {
                base.OnMouseDragEnd(cancel);
            }
        }
    }
}