public selectedVertex inside(int index, Point target)
        {
            //find shortest dist
            selectedVertex result = new selectedVertex();
            double         distance = double.MaxValue, buff;

            result.vertex = new Point(-1, -1);
            foreach (var i in vertexes[index])
            {
                buff = Schemes_Editor.distance(i, target);
                if (buff < 30 && buff < distance)
                {
                    result.vertex = i;
                    distance      = buff;
                }
            }
            bool firstTime = true;

            for (int i = 1; i < points[index].Count - 1; i++)
            {
                buff = Schemes_Editor.distance(points[index][i], target);
                if (buff < 30 && (buff < distance || firstTime))
                {
                    firstTime            = false;
                    distance             = buff;
                    result.vertex        = points[index][i];
                    result.isExists      = true;
                    result.ExistingIndex = i;
                }
            }
            return(result);
        }
        static public void MOVE(object sender, MouseEventArgs e)
        {
            mousePosition = e.Location;
            switch (Mode)
            {
            case modeStruct.moveVinosku:
                float distt = Math.Abs(movable.vinoska[localSheet].vertex1.X - movable.vinoska[localSheet].vertex2.X);
                movable.vinoska[localSheet].vertex1 = new Point((int)(e.Location.X - distt / 2.0f), e.Location.Y);
                movable.vinoska[localSheet].vertex2 = new Point((int)(e.Location.X + distt / 2.0f), e.Location.Y);

                if (movable.vinoska[localSheet].vertex2.X < movable.vinoska[localSheet].startPoint.X)
                {
                    Point t = movable.vinoska[localSheet].vertex1;
                    movable.vinoska[localSheet].vertex1 = movable.vinoska[localSheet].vertex2;
                    movable.vinoska[localSheet].vertex2 = t;
                }
                break;

            case modeStruct.dragVertex:
                Schemes_Editor.wires[SelectedWireIndex].points[localSheet][VertexNumber] = new Point(e.Location.X, e.Location.Y);
                break;

            case modeStruct.moveRoom:
                movable.move(new Point(e.X - Prev.X, e.Y - Prev.Y), localSheet);
                break;

            case modeStruct.doNothing_NOSCALEMODE:
                indexToSurround = -1;
                isRoomSelected  = false;
                isWireSelected  = false;

                for (int i = 0; i < Schemes_Editor.wires.Count; i++)
                {
                    selectedVertex ver = Schemes_Editor.wires[i].inside(localSheet, e.Location);
                    if (ver.vertex.X != -1)
                    {
                        isWireSelected    = true;
                        SelectedWireIndex = i;
                        break;
                    }
                }
                if (isWireSelected)
                {
                    break;
                }
                for (int i = Schemes_Editor.mainWorkList.Count - 1; i > -1; i--)
                {
                    if (Schemes_Editor.mainWorkList[i] is inboxes)
                    {
                        continue;
                    }

                    if (Schemes_Editor.mainWorkList[i].inside(e.Location, localSheet))
                    {
                        indexToSurround = i;
                        break;
                    }
                }
                if (indexToSurround != -1)
                {
                    break;
                }
                else
                {
                    for (int i = 0; i < Schemes_Editor.rooms.Count; i++)
                    {
                        if (Schemes_Editor.rooms[i].inside(e.Location, localSheet))
                        {
                            isRoomSelected  = true;
                            indexToSurround = i;
                            break;
                        }
                    }
                }
                break;


            case modeStruct.doNothing_SCALEMODE:
                scalePoint = new Point(-1, -1);
                //finding nearest dots
                for (int i = 0; i < Schemes_Editor.mainWorkList.Count; i++)
                {
                    //if (Schemes_Editor.mainWorkList[i] is wire_s)
                    //    continue;
                    if (Schemes_Editor.mainWorkList[i] is inboxes && ((inboxes)Schemes_Editor.mainWorkList[i]).inbox)
                    {
                        continue;
                    }
                    else
                    {
                        int a = Schemes_Editor.mainWorkList[i].locations[localSheet].X, b = Schemes_Editor.mainWorkList[i].locations[localSheet].Y, c = Schemes_Editor.mainWorkList[i].locations[localSheet].X + Schemes_Editor.mainWorkList[i].scales[localSheet].X, d = Schemes_Editor.mainWorkList[i].locations[localSheet].Y + Schemes_Editor.mainWorkList[i].scales[localSheet].Y;
                        if (Schemes_Editor.distance(new Point(a, b), e.Location) < 20)
                        {
                            scalePoint = new Point(a, b);
                            break;
                        }
                        if (Schemes_Editor.distance(new Point(a, d), e.Location) < 20)
                        {
                            scalePoint = new Point(a, d);
                            break;
                        }
                        if (Schemes_Editor.distance(new Point(c, b), e.Location) < 20)
                        {
                            scalePoint = new Point(c, b);
                            break;
                        }
                        if (Schemes_Editor.distance(new Point(c, d), e.Location) < 20)
                        {
                            scalePoint = new Point(c, d);
                            break;
                        }
                    }
                }
                if (scalePoint.X != -1)
                {
                    break;
                }
                else
                {
                    for (int i = 0; i < Schemes_Editor.rooms.Count; i++)
                    {
                        int a = Schemes_Editor.rooms[i].locations[localSheet].X, b = Schemes_Editor.rooms[i].locations[localSheet].Y, c = Schemes_Editor.rooms[i].locations[localSheet].X + Schemes_Editor.rooms[i].locations[localSheet].Width, d = Schemes_Editor.rooms[i].locations[localSheet].Y + Schemes_Editor.rooms[i].locations[localSheet].Height;
                        if (Schemes_Editor.distance(new Point(a, b), e.Location) < 20)
                        {
                            scalePoint = new Point(a, b);
                            break;
                        }
                        if (Schemes_Editor.distance(new Point(a, d), e.Location) < 20)
                        {
                            scalePoint = new Point(a, d);
                            break;
                        }
                        if (Schemes_Editor.distance(new Point(c, b), e.Location) < 20)
                        {
                            scalePoint = new Point(c, b);
                            break;
                        }
                        if (Schemes_Editor.distance(new Point(c, d), e.Location) < 20)
                        {
                            scalePoint = new Point(c, d);
                            break;
                        }
                    }
                }
                break;

            case modeStruct.dragShkaf:
                movable.move(new Point(e.Location.X - Prev.X, e.Location.Y - Prev.Y), localSheet);
                break;

            case modeStruct.dragShkafnoe:
                movable.move(new Point(e.Location.X - Prev.X, e.Location.Y - Prev.Y), localSheet);
                break;

            case modeStruct.scaleSomething:
                if (isRoomSelected)
                {
                    var buff = Schemes_Editor.rooms[moveTargetIndex];
                    if (pointNum == 0)
                    {
                        //num 3
                        Point p = new Point(buff.locations[localSheet].X + buff.locations[localSheet].Width, buff.locations[localSheet].Y + buff.locations[localSheet].Height);

                        buff.locations[localSheet] = new Rectangle(e.Location.X, e.Location.Y, p.X - e.Location.X, p.Y - e.Location.Y);

                        scalePoint = e.Location;
                    }
                    if (pointNum == 1)
                    {
                        //num 3
                        Point p = new Point(buff.locations[localSheet].X, buff.locations[localSheet].Y + buff.locations[localSheet].Height);

                        buff.locations[localSheet] = new Rectangle(buff.locations[localSheet].X, e.Location.Y, e.Location.X - p.X, p.Y - e.Location.Y);

                        scalePoint = e.Location;
                    }
                    if (pointNum == 2)
                    {
                        //num 3
                        buff.locations[localSheet] = new Rectangle(buff.locations[localSheet].X, buff.locations[localSheet].Y, e.Location.X - buff.locations[localSheet].X, e.Location.Y - buff.locations[localSheet].Y);
                        // buff.locations[2] = e.Location;
                        scalePoint = e.Location;
                    }
                    if (pointNum == 3)
                    {
                        //num 3
                        Point p = new Point(buff.locations[localSheet].X + buff.locations[localSheet].Width, buff.locations[localSheet].Y);

                        buff.locations[localSheet] = new Rectangle(e.Location.X, p.Y, p.X - e.Location.X, e.Location.Y - p.Y);

                        scalePoint = e.Location;
                    }
                }
                else
                {
                    var buff = Schemes_Editor.mainWorkList[moveTargetIndex];
                    if (pointNum == 0)
                    {
                        //num 3
                        Point p = new Point(buff.locations[localSheet].X + buff.scales[localSheet].X, buff.locations[localSheet].Y + buff.scales[localSheet].Y);
                        buff.scales[localSheet]    = new Point(p.X - e.Location.X, p.Y - e.Location.Y);
                        buff.locations[localSheet] = e.Location;
                        scalePoint = e.Location;
                    }
                    if (pointNum == 1)
                    {
                        //num 3
                        Point p = new Point(buff.locations[localSheet].X, buff.locations[localSheet].Y + buff.scales[localSheet].Y);
                        buff.scales[localSheet]    = new Point(e.Location.X - p.X, p.Y - e.Location.Y);
                        buff.locations[localSheet] = new Point(e.Location.X - buff.scales[localSheet].X, e.Location.Y);
                        scalePoint = e.Location;
                    }
                    if (pointNum == 2)
                    {
                        //num 3
                        buff.scales[localSheet] = new Point(e.Location.X - buff.locations[localSheet].X, e.Location.Y - buff.locations[localSheet].Y);
                        // buff.locations[2] = e.Location;
                        scalePoint = e.Location;
                    }
                    if (pointNum == 3)
                    {
                        //num 3
                        Point p = new Point(buff.locations[localSheet].X + buff.scales[localSheet].X, buff.locations[localSheet].Y);
                        buff.scales[localSheet]    = new Point(p.X - e.Location.X, e.Location.Y - p.Y);
                        buff.locations[localSheet] = new Point(e.Location.X, p.Y);
                        scalePoint = e.Location;
                    }
                }
                break;
            }
            draw();
        }