Example #1
0
 // Gan cac gia tri cho m_Shape
 private void Gan(CShape shape)
 {
     shape.SetDrawMode(GDI.R2_NOTXORPEN);
     shape.SetWidth(int.Parse(tcmbWidth.SelectedItem.ToString()));
     shape.SetPenStyle(Chon(tcmbPenStyle.SelectedItem.ToString()));
     shape.SetColor(_RGB(m_R, m_G, m_B));
 }
Example #2
0
        private void panel1_MouseDown(object sender, MouseEventArgs e)
        {
            flag = !flag;
            if (flag) // bat dau ve
            {
                tlbl.Visible         = false;
                tcmbPenStyle.Enabled = false;
                tcmbWidth.Enabled    = false;
                m_Start.x            = m_End.x = e.X;
                m_Start.y            = m_End.y = e.Y;
                if (m_Shape.ToString() == "CPolygon")
                {
                    HDC        hdc = (HDC)User.GetDC(panel1.Handle);
                    CRectangle rec = new CRectangle(m_End.x - distance, m_End.y - distance, m_End.x + distance, m_End.y + distance);
                    rec.SetDrawMode(GDI.R2_NOTXORPEN);
                    rec.Draw(hdc);
                    User.ReleaseDC(panel1.Handle, hdc);

                    m_arrPoint    = new POINT[1];
                    m_arrPoint[0] = m_End;
                }
            }
            else
            {
                HDC hdc = (HDC)User.GetDC(panel1.Handle);
                if (m_Shape.ToString() == "CPolygon")
                {
                    if (e.Clicks != 2)
                    {
                        m_Start = m_End;
                        flag    = !flag;
                        CRectangle rec = new CRectangle(m_End.x - distance, m_End.y - distance, m_End.x + distance, m_End.y + distance);
                        rec.SetDrawMode(GDI.R2_NOTXORPEN);
                        rec.Draw(hdc);
                        User.ReleaseDC(panel1.Handle, hdc);

                        Array.Resize <POINT>(ref m_arrPoint, m_arrPoint.Length + 1);
                        m_arrPoint[m_arrPoint.Length - 1] = m_End;
                        return;
                    }
                    else
                    {
                        m_Shape.SetPoints(m_arrPoint);
                        foreach (POINT t in m_arrPoint)
                        {
                            CRectangle rec = new CRectangle(t.x - distance, t.y - distance, t.x + distance, t.y + distance);
                            rec.SetDrawMode(GDI.R2_NOTXORPEN);
                            rec.Draw(hdc);
                        }
                        m_arrPoint = null;
                    }
                }

                m_Shape.SetDrawMode(GDI.R2_COPYPEN);
                m_Shape.Draw(hdc);

                // Them hinh vao tap hop
                if (m_arrShape == null)
                {
                    m_arrShape = new CShape[1];
                }
                else
                {
                    Array.Resize <CShape>(ref m_arrShape, m_arrShape.Length + 1);
                }
                m_arrShape[m_arrShape.Length - 1] = m_Shape;

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

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

                case "CPolygon":
                    m_Shape = new CPolygon();
                    break;

                case "CRectangle":
                    m_Shape = new CRectangle();
                    break;
                }
                Gan(m_Shape);

                User.ReleaseDC(panel1.Handle, hdc);

                tcmbPenStyle.Enabled = true;
                tcmbWidth.Enabled    = true;
                tlbl.Visible         = true;
            }
        }