예제 #1
0
 private void btnTinh_Click(object sender, EventArgs e)
 {
     try
     {
         double      canhA = double.Parse(txtCanhA.Text);
         double      canhB = double.Parse(txtCanhB.Text);
         double      canhC = double.Parse(txtCanhC.Text);
         HinhTamGiac htg   = new HinhTamGiac();
         htg.CanhA     = canhA;
         htg.CanhB     = canhB;
         htg.CanhC     = canhC;
         lblChuVi.Text =
             String.Format("Chu Vi: {0}", htg.ChuVi());
         lblDienTich.Text =
             String.Format("Diện Tích: {0}", htg.DienTich());
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
예제 #2
0
        private void panel2_MouseClick(object sender, MouseEventArgs e)
        {
            int x = e.X;
            int y = e.Y;

            if (chedo == 1)
            {
                this.rsPoint();
                if (hinh == 1) //hcn
                {
                    if (p1.X == -1)
                    {
                        p1.X = Pixel.RoundPixel(x);
                        p1.Y = Pixel.RoundPixel(y);
                        Pixel.HienThi(p1, g, this.color);
                    }
                    else if (p2.X == -1)
                    {
                        p2.X = Pixel.RoundPixel(x);
                        p2.Y = Pixel.RoundPixel(y);


                        HinhChuNhat hcn = new HinhChuNhat(p1, p2, this.color);

                        //this.AX.Text = "( " + hcn.A.X/5 + " , " + hcn.A.Y/5 + " )";
                        //this.BX.Text = "( " + hcn.B.X/5 + " , " + hcn.B.Y/5 + " )";
                        //this.CX.Text = "( " + hcn.C.X/5 + " , " + hcn.C.Y/5 + " )";
                        //this.DX.Text = "( " + hcn.D.X/5 + " , " + hcn.D.Y/5 + " )";

                        this.AX.Text = Pixel.chuyenToaDoNgDg(hcn.A);
                        this.BX.Text = Pixel.chuyenToaDoNgDg(hcn.B);
                        this.CX.Text = Pixel.chuyenToaDoNgDg(hcn.C);
                        this.DX.Text = Pixel.chuyenToaDoNgDg(hcn.D);

                        hcn.Draw(g);
                        p1.X = -1;
                        p2.X = -1;
                    }
                }
                else if (hinh == 2) //eclip
                {
                    if (p1.X == -1)
                    {
                        p1.X = Pixel.RoundPixel(x);
                        p1.Y = Pixel.RoundPixel(y);
                        Pixel.HienThi(p1, g, this.color);
                    }
                    else if (p2.X == -1)
                    {
                        p2.X = Pixel.RoundPixel(x);
                        p2.Y = p1.Y;
                        Pixel.HienThi(p2, g, this.color);
                    }
                    else if (p3.X == -1)
                    {
                        p3.X = p1.X;
                        p3.Y = Pixel.RoundPixel(y);

                        this.AX.Text = Pixel.chuyenToaDoNgDg(p1);
                        this.BX.Text = Pixel.chuyenToaDoNgDg(p2);
                        this.CX.Text = Pixel.chuyenToaDoNgDg(p3);

                        Pixel.HienThi(p1, g, color);
                        int  a  = Pixel.distancePoint(p1, p2);
                        int  b  = Pixel.distancePoint(p1, p3);
                        Elip el = new Elip(p1, a, b, this.color);



                        el.Draw(g);


                        p1.X = -1;
                        p2.X = -1;
                        p3.X = -1;
                    }
                }
                else if (hinh == 3) //tron
                {
                    if (p1.X == -1)
                    {
                        p1.X = Pixel.RoundPixel(x);
                        p1.Y = Pixel.RoundPixel(y);
                        Pixel.HienThi(p1, g, this.color);
                    }
                    else if (p2.X == -1)
                    {
                        p2.X = Pixel.RoundPixel(x);
                        p2.Y = Pixel.RoundPixel(y);

                        this.AX.Text = Pixel.chuyenToaDoNgDg(p1);
                        this.BX.Text = Pixel.chuyenToaDoNgDg(p2);

                        Pixel.HienThi(p1, g, color);
                        HinhTron ht = new HinhTron(Pixel.distancePoint(p1, p2), p1, this.color);
                        ht.Draw(g);
                        p1.X = -1;
                        p2.X = -1;
                    }
                }
                else if (hinh == 4) //tam giac
                {
                    if (p1.X == -1)
                    {
                        p1.X = Pixel.RoundPixel(x);
                        p1.Y = Pixel.RoundPixel(y);
                        Pixel.HienThi(p1, g, this.color);
                    }
                    else if (p2.X == -1)
                    {
                        p2.X = Pixel.RoundPixel(x);
                        p2.Y = Pixel.RoundPixel(y);
                        Pixel.HienThi(p2, g, this.color);
                    }
                    else if (p3.X == -1)
                    {
                        p3.X = Pixel.RoundPixel(x);
                        p3.Y = Pixel.RoundPixel(y);

                        this.AX.Text = Pixel.chuyenToaDoNgDg(p1);
                        this.BX.Text = Pixel.chuyenToaDoNgDg(p2);
                        this.BX.Text = Pixel.chuyenToaDoNgDg(p3);
                        HinhTamGiac htg = new HinhTamGiac(p1, p2, p3, color);
                        htg.Draw(g);

                        p1.X = -1;
                        p2.X = -1;
                        p3.X = -1;
                    }
                }
                else if (hinh == 5) //line
                {
                    if (p1.X == -1)
                    {
                        p1.X = Pixel.RoundPixel(x);
                        p1.Y = Pixel.RoundPixel(y);
                        Pixel.HienThi(p1, g, color);
                    }
                    else if (p2.X == -1)
                    {
                        p2.X = Pixel.RoundPixel(x);
                        p2.Y = Pixel.RoundPixel(y);

                        this.AX.Text = Pixel.chuyenToaDoNgDg(p1);
                        this.BX.Text = Pixel.chuyenToaDoNgDg(p2);
                        Line l = new Line(p1, p2, color);
                        l.Draw(g);
                        p1.X = -1;
                        p2.X = -1;
                    }
                }
                else if (hinh == 6)
                {
                    if (p1.X == -1)
                    {
                        p1.X = Pixel.RoundPixel(x);
                        p1.Y = Pixel.RoundPixel(y);
                        Pixel.HienThi(p1, g, color);
                    }
                    else if (p2.X == -1)
                    {
                        p2.X = p1.X;
                        p2.Y = Pixel.RoundPixel(y);

                        this.AX.Text = Pixel.chuyenToaDoNgDg(p1);
                        this.BX.Text = Pixel.chuyenToaDoNgDg(p2);

                        Pixel.HienThi(p1, g, Color.White);
                        Star star = new Star(p1, Math.Abs(p1.Y - p2.Y), color);
                        star.Draw(g);

                        p1.X = -1;
                        p2.X = -1;
                    }
                }
            }
            else if (chedo == 2)
            {
            }
        }