예제 #1
0
        private void panel1_Paint(object sender, PaintEventArgs e)
        {
            HDC hdc = (HDC)User.GetDC(panel1.Handle);

            if (m_arrShape != null)
            {
                foreach (CShape t in m_arrShape)
                {
                    t.Draw(hdc);
                }
            }

            if (flag)
            {
                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_COPYPEN);
                    rec.Draw(hdc);

                    POINT[] t1 = new POINT[2];
                    t1[1] = m_arrPoint[0];
                    CLine line = new CLine();
                    line.SetDrawMode(GDI.R2_COPYPEN);
                    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 panel1_MouseMove(object sender, MouseEventArgs e)
        {
            toolStripStatusLabel1.Text = e.X.ToString() + " : " + e.Y.ToString();

            if (flag)
            {
                POINT[] T = new POINT[2];
                T[0] = m_Start;
                T[1] = m_End;
                HDC hdc = (HDC)User.GetDC(panel1.Handle);

                if (flag1 == false)
                {
                    if (m_Shape.ToString() == "CPolygon")
                    {
                        CShape shape = new CLine();
                        shape.SetPoints(T);
                        Gan(shape);
                        shape.Draw(hdc);
                    }
                    else
                    {
                        m_Shape.SetPoints(T);
                        m_Shape.Draw(hdc);
                    }
                }

                flag1 = false;
                if (m_Shape.ToString() == "CEllipse")
                {
                    int temp = Math.Min(Math.Abs(e.X - m_Start.x), Math.Abs(e.Y - m_Start.y));
                    m_End.x = m_Start.x + Math.Sign(e.X - m_Start.x) * temp;
                    m_End.y = m_Start.y + Math.Sign(e.Y - m_Start.y) * temp;
                }
                else
                {
                    m_End.x = e.X;
                    m_End.y = e.Y;
                }

                T[1] = m_End;
                if (m_Shape.ToString() == "CPolygon")
                {
                    CShape shape = new CLine();
                    shape.SetPoints(T);
                    Gan(shape);
                    shape.Draw(hdc);
                }
                else
                {
                    m_Shape.SetPoints(T);
                    m_Shape.Draw(hdc);
                }
            }
        }