Exemplo n.º 1
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);
                }
            }
        }
Exemplo n.º 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;
                }
            }
        }