Пример #1
0
        // Xoa hinh dang ve
        private void Xoa()
        {
            if (flag)
            {
                HDC hdc = (HDC)User.GetDC(panel1.Handle);
                if (m_Shape.ToString() == "CPolygon" && m_arrPoint != null)
                {
                    POINT[] t = new POINT[2];
                    t[0].x = m_arrPoint[0].x - distance;
                    t[0].y = m_arrPoint[0].y - distance;
                    t[1].x = m_arrPoint[0].x + distance;
                    t[1].y = m_arrPoint[0].y + distance;
                    CRectangle rec = new CRectangle(t[0], t[1]);
                    rec.SetDrawMode(GDI.R2_NOTXORPEN);
                    rec.Draw(hdc);

                    POINT[] t1 = new POINT[2];
                    t1[1] = m_arrPoint[0];
                    CLine line = new CLine();
                    Gan(line);
                    for (int i = 1; i < m_arrPoint.Length; ++i)
                    {
                        // Ve duong thang
                        t1[0] = t1[1];
                        t1[1] = m_arrPoint[i];
                        line.SetPoints(t1);
                        line.Draw(hdc);
                        // Ve o vuong nho tai cac dinh
                        t[0].x = m_arrPoint[i].x - distance;
                        t[0].y = m_arrPoint[i].y - distance;
                        t[1].x = m_arrPoint[i].x + distance;
                        t[1].y = m_arrPoint[i].y + distance;
                        rec.SetPoints(t);
                        rec.Draw(hdc);
                    }

                    // Ve duong thang
                    t1[0] = t1[1];
                    t1[1] = m_End;
                    line.SetPoints(t1);
                    line.Draw(hdc);
                }
                else
                {
                    m_Shape.Draw(hdc);
                }
                User.ReleaseDC(panel1.Handle, hdc);
            }
        }
Пример #2
0
        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            m_End.X = e.X;
            m_End.Y = e.Y;
            flag    = !flag;
            if (flag) // bat dau ve
            {
                m_Start.X = e.X;
                m_Start.Y = e.Y;
            }
            else
            {
                // Chuyen toa do 2 diem thanh mang cac diem
                Point[] T = new Point[2];
                T[0] = m_Start;
                T[1] = m_End;

                // Them tham so cho hinh can ve
                m_Shape.SetPoints(T);
                m_Shape._Color = m_Color;
                m_Shape.Fill   = m_Fill;

                // Ve
                Graphics grImage = Graphics.FromImage(bmpNew);
                Graphics gr      = this.CreateGraphics();
                m_Shape.Draw(gr);      // ve len man hinh
                m_Shape.Draw(grImage); // ve len anh (trong vung nho)
                gr.Dispose();
                grImage.Dispose();

                // Them hinh vao tap hop
                m_arrShape.Add(m_Shape);

                switch (m_Shape.ToString())
                {
                case "CLine":
                    m_Shape = new CLine();
                    break;

                case "CEllipse":
                    m_Shape = new CEllipse();
                    break;
                }
            }
        }