private void btnTinh_Click(object sender, EventArgs e) { try { double banKinh = double.Parse(txtBanKinh.Text); HinhTron ht = new HinhTron(); ht.BanKinh = banKinh; lblChuVi.Text = String.Format("Chu Vi: {0}", ht.ChuVi()); lblDienTich.Text = String.Format("Diện Tích: {0}", ht.DienTich()); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
static void Main(string[] args) { HinhHoc2D hinhTron = new HinhTron(10); hinhTron.tinhChuVi(); hinhTron.tinhDienTich(); hinhTron.inTen(); hinhTron.inChuVi(); hinhTron.inDienTich(); Console.WriteLine("Hinh Tron is Hinh Hoc 2D: " + (hinhTron is HinhHoc2D)); HinhHoc2D hinh = new HinhHoc2D(); hinh.tinhChuVi(); hinh.tinhDienTich(); hinh.inTen(); hinh.inChuVi(); hinh.inDienTich(); Console.WriteLine("Hinh Hoc 2D is Hinh Tron: " + (hinh is HinhTron)); Console.ReadLine(); }
private void Button_MouseDown(object sender, MouseEventArgs e) { Button btn = sender as Button; if (btn.Tag.Equals("Circle")) { CircleProperties circleProperties = new CircleProperties(this.pnl_Tb_2D.Size); circleProperties.PropertyChanged += CircleProperties_PropertyChanged; this.pnl_ToolBox.Controls.Add(circleProperties); circleProperties.BringToFront(); ht = new HinhTron(new Point(550, 320), 10); circleProperties.CoorOriginal = ToaDo.MayTinhNguoiDung(new Point(550, 320)); circleProperties.Radius = 10; ht.Draw(picb_2DArea.CreateGraphics()); ht.PropertyChanged += Ht_PropertyChanged; } else if (btn.Tag.Equals("Clock")) { clockProperties = new ClockProperties(); clockProperties.PropertyChanged += ClockProperties_PropertyChanged; this.pnl_ToolBox.Controls.Add(clockProperties); if (flagXe == false) { clockProperties.Refresh(); } clockProperties.BringToFront(); DateTime dt = DateTime.Now; clock = new Clock(new Point(0, 0), 15, dt); clock.CurrentDatetime = new DateTime(2019, 05, 19, 12, 30, 15); clock.Draw(this.picb_2DArea.CreateGraphics()); clock.PropertyChanged += Clock_PropertyChanged; } else if (btn.Tag.Equals("TimePiece")) { timepieceProperties = new TimepieceProperties(); timepieceProperties.PropertyChanged += TimepieceProperties_PropertyChanged; this.pnl_ToolBox.Controls.Add(timepieceProperties); timepieceProperties.BringToFront(); timepiece = new Timepiece(); timepiece.PropertyChanged += Timepiece_PropertyChanged; } else if (btn.Tag.Equals("Car")) { this.timer1.Start(); xe = new XeProperties(); flagXe = true; hinhXe = new HinhXe(); this.pnl_ToolBox.Controls.Add(xe); xe.BringToFront(); xe.Visible = true; xe.PropertyChanged += Xe_PropertyChanged; //if (flagXe) //{ // // biểu diễn các hoạt động của xe // hinhXe.PropertyChanged += HinhXe_PropertyChanged; // hinhXe.ToMau(e.Graphics); // hinhXe.drawCar(e.Graphics); // if (dem <= 30) // { // dem++; // // tịnh tiến 5 đơn vị // // đi phải qua trái // hinhXe.traslationXe(5, 0); // hinhXe.quayBanhXe(30); // } // else if (dem <= 60) // { // dem++; // //tịnh tiến 5 đơn vị // // đi phải qua trái // hinhXe.traslationXe(0, 5); // hinhXe.quayBanhXe(30); // } // else if (dem <= 90) // { // dem++; // // đi từ trên xuống dưới // hinhXe.traslationXe(-5, 0); // hinhXe.quayBanhXe(-30); // } // else if (dem <= 120) // { // dem++; // // đi từ dưới lên trên // hinhXe.traslationXe(0, -5); // hinhXe.quayBanhXe(-30); // }else // { // // cập nhật lại // dem = 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) { } }