protected override void WndProc(ref Message m)
        {
            if (m.Msg == WM_SIZING && m.HWnd.Equals(this.Handle))
            {
                Rect r = new Rect();
                r = (Rect)Marshal.PtrToStructure(m.LParam, r.GetType());

                double width = r.Right - r.Left;
                double height = r.Bottom - r.Top;

                if (height / width > aspect_ratio((int)width))
                    width = height / aspect_ratio((int)width);
                else
                    height = width * aspect_ratio((int)width);

                if (m.WParam.ToInt32() == WMSZ_TOP || m.WParam.ToInt32() == WMSZ_TOPLEFT || m.WParam.ToInt32() == WMSZ_TOPRIGHT)
                    r.Top = r.Bottom - (int)height;
                else
                    r.Bottom = r.Top + (int)height;

                if (m.WParam.ToInt32() == WMSZ_LEFT || m.WParam.ToInt32() == WMSZ_TOPLEFT || m.WParam.ToInt32() == WMSZ_BOTTOMLEFT)
                    r.Left = r.Right - (int)width;
                else
                    r.Right = r.Left + (int)width;

                Marshal.StructureToPtr(r, m.LParam, true);
            }

            base.WndProc(ref m);
        }
示例#2
0
 public void copy(Shape s)
 {
     Shape temp;
     if (s!=null)
     {
         temp = new Rect(0,0,1,1,Color.Black);
         //is s a rectangle...?
         if (temp.GetType() == s.GetType()) temp = new Rect((Rect)s);
         else
         {
             //is it an oval...?
             temp = new Oval(0,0,1,1,Color.Black);
             if (temp.GetType() == s.GetType()) temp = new Oval((Oval)s);
             else
             {
                 //is it a line...?
                 temp = new Segment(0,0,1,1,Color.Black,1);
                 if (temp.GetType() == s.GetType()) temp = new Segment((Segment)s);
                 else
                 {
                     //is it a triangle...?
                     Point p1 = new Point();
                     Point p2 = new Point();
                     Point p3 = new Point();
                     temp = new Triangle(p1,p2,p3,Color.Black);
                     if (temp.GetType() == s.GetType()) temp = new Triangle((Triangle)s);
                 }
             }
         }
         //put the brand new copy into myShapes right after(above in the picture) the original
         myShapes.Insert(myShapes.IndexOf(s)+1,temp);
     }
     //if s is null, do nothing
     return;
 }