Esempio n. 1
0
 private void Form1_MouseUp(object sender, MouseEventArgs e)
 {
     if (estado == EstadoActual.rectangulo && dibujando == true)
     {
         rectangulo r = new rectangulo(tempx, tempy, e.X - tempx, e.Y - tempy);
         dibujando = false;
         r.Dibuja(this);
         figura.Add(r);
     }
     else if (estado == EstadoActual.elipse && dibujando == true)
     {
         elipse c = new elipse(tempx, tempy, e.X - tempx, e.Y - tempy);
         dibujando = false;
         c.Dibuja(this);
         figura.Add(c);
     }
     else if (estado == EstadoActual.linea && dibujando == true)
     {
         dibujando        = false;
         this.label1.Text = string.Format("X={0}  Y={1}", tempx, tempy);
         linea l = new linea(tempx, tempy, e.X, e.Y);
         l.Dibuja(this);
         figura.Add(l);
     }
 }
Esempio n. 2
0
        private void panel1_MouseClick(object sender, MouseEventArgs e)
        {
            if (hinh == -1)
            {
                MessageBox.Show("Chọn hình để vẽ trước");
                this.Refresh();
                return;
            }
            mouse.X -= 179;
            mouse.Y -= 152;
            int a = mouse.X - 375;
            int b = mouse.Y - 250;

            g.FillRectangle(brush, mouse.X, mouse.Y, 3, 3);
            diem[i] = new Point(a + 375, b + 250);

            //duong thang

            //ve hinh binh hanh
            if (hinh == 0)
            {
                int temp = i + 1;
                if (i > 0)
                {
                    if (temp % 4 == 0)
                    {
                        //ve hinh thang mat tren cua hinh hop
                        Line  AB = new Line(0, 0, 0, 0, Color.Black);
                        Line  BC = new Line(0, 0, 0, 0, Color.Black);
                        Line  CD = new Line(0, 0, 0, 0, Color.Black);
                        Line  DA = new Line(0, 0, 0, 0, Color.Black);
                        Point D  = new Point();
                        D.X = diem[i - 2].X;
                        D.Y = diem[i - 3].Y;
                        Point C = new Point();
                        C.X = diem[i - 1].X - (diem[i - 3].X - diem[i - 2].X);
                        C.Y = diem[i - 1].Y;
                        AB.setdiemdau(diem[i - 3]);
                        AB.setdiemcuoi(diem[i - 1]);
                        BC.setdiemdau(diem[i - 1]);
                        BC.setdiemcuoi(C);
                        CD.setdiemdau(C);
                        CD.setdiemcuoi(D);
                        DA.setdiemdau(D);
                        DA.setdiemcuoi(diem[i - 3]);
                        AB.DDA_Line(this.panel1.CreateGraphics());
                        BC.DDA_Line(this.panel1.CreateGraphics());
                        CD.DDA_Line(this.panel1.CreateGraphics());
                        DA.DDA_Line(this.panel1.CreateGraphics());

                        // ve hinh thang mat day hop
                        Line  EF = new Line(0, 0, 0, 0, Color.Black);
                        Line  FG = new Line(0, 0, 0, 0, Color.Black);
                        Line  GH = new Line(0, 0, 0, 0, Color.Black);
                        Line  HE = new Line(0, 0, 0, 0, Color.Black);
                        Point E  = new Point();
                        E.X = diem[i - 3].X;
                        E.Y = diem[i].Y;
                        Point F = new Point();
                        F.X = diem[i - 1].X;
                        F.Y = C.Y - (diem[i - 3].Y - E.Y);
                        Point G = new Point();
                        G.X = C.X;
                        G.Y = C.Y - (diem[i - 3].Y - E.Y);
                        Point H = new Point();
                        H.X = D.X;
                        H.Y = diem[i].Y;
                        EF.setdiemdau(E);
                        EF.setdiemcuoi(F);
                        FG.setdiemdau(F);
                        FG.setdiemcuoi(G);
                        GH.setdiemdau(G);
                        GH.setdiemcuoi(H);
                        HE.setdiemdau(H);
                        HE.setdiemcuoi(E);
                        EF.DDA_Line(this.panel1.CreateGraphics());
                        FG.DDA_Line(this.panel1.CreateGraphics());
                        GH.DDA_Line_NetDut(this.panel1.CreateGraphics());
                        HE.DDA_Line_NetDut(this.panel1.CreateGraphics());
                        //noi 2 hinh nop lai voi nhau
                        Line AE = new Line(diem[i - 3].X, diem[i - 3].Y, E.X, E.Y, Color.Black);
                        Line BF = new Line(diem[i - 1].X, diem[i - 1].Y, F.X, F.Y, Color.Black);
                        Line CG = new Line(C.X, C.Y, G.X, G.Y, Color.Black);
                        Line DH = new Line(D.X, D.Y, H.X, H.Y, Color.Black);
                        AE.DDA_Line(this.panel1.CreateGraphics());
                        BF.DDA_Line(this.panel1.CreateGraphics());
                        CG.DDA_Line(this.panel1.CreateGraphics());
                        DH.DDA_Line_NetDut(this.panel1.CreateGraphics());
                    }
                }
            }
            //ve hinh cau
            else if (hinh == 1)
            {
                if (i > 0)
                {
                    if (i % 2 != 0)
                    {
                        int    r  = Math.Abs(diem[i].X - diem[i - 1].X);
                        circle tr = new circle(diem[i].X, diem[i].Y, r);
                        tr.drawC(g);
                        elipse elip = new elipse(diem[i], r, r / 2);
                        elip.Midpoint_elipse1(g);
                    }
                }
            }
            i++;
        }