Ejemplo n.º 1
0
        protected void buttonHinhVuong_Click(object sender, EventArgs e)
        {
            HinhVuong hv = new HinhVuong();

            hv.Canh            = 5000;
            textBoxKetQua.Text = hv.XuatThongTin();
        }
        protected void btnTinh_Click(object sender, EventArgs e)
        {
            // Ứng dụng kỹ thuật Late Binding
            IHinh h;

            if (rdbHinhVuong.Checked)
            {
                double c = double.Parse(txtCanh.Text);
                h = new HinhVuong {
                    Canh = c
                };
            }
            else
            {
                double d = double.Parse(txtChieuDai.Text);
                double r = double.Parse(txtChieuRong.Text);
                h = new HinhChuNhat {
                    ChieuDai = d, ChieuRong = r
                };
            }
            txtKetQua.Text = h.XuatThongTin();
        }
        protected void btnTinh_Click(object sender, EventArgs e)
        {
            IHinh hinh;

            if (rdbHinhVuong.Checked)
            {
                //hinh = new HinhVuong// do tạo constructors nên dùng gán bằng cách gọi thuộc tính
                //{
                //    Canh = double.Parse(txtCanh.Text)
                //};

                double canh = double.Parse(txtCanh.Text);
                hinh = new HinhVuong(canh);
            }
            else
            {
                hinh = new HinhChuNhat
                {
                    ChieuDai  = double.Parse(txtChieuDai.Text),
                    ChieuRong = double.Parse(txtChieuRong.Text)
                };
            }
        }