コード例 #1
0
 private void PictureBox_Mouse_Down(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Left)
     {
         if (isMoving)
         {
             //đang di chuyển hình
         }
         else
         {
             if (hinhHienTai == null || hinhHienTai.KiemTraViTri(e.Location) == -1)
             {
                 hinhHienTai = LayHinhVeHienTai(IDhinhHienTai);
             }
             if (hinhHienTai != null)
             {
                 hinhHienTai.Mouse_Down(e);                            //gọi sự kiện mouse_down của hình
                 pictureBox.Refresh();                                 //làm mới
                 hinhHienTai.VeKhung(pictureBox.CreateGraphics());     //vẽ 8 hình chữ nhật nhỏ (chấm vuông nhỏ) làm khung xung quanh
                 lHV.listHinh.Insert(lHV.listHinh.Count, hinhHienTai); //thêm hình mới vào list
             }
         }
     }
     else
     {
         hinhHienTai = null;
     }
 }
コード例 #2
0
        private void BtnxCopy_Click(object sender, EventArgs e)
        {
            if (hinhHienTai != null && hinhHienTai.loaiHinh != 0)
            {
                switch (hinhHienTai.loaiHinh)
                {
                case 1: hinhCopy = new Elip(); Copy(hinhHienTai, hinhCopy);
                    break;

                case 2: hinhCopy = new HinhChuNhat(); Copy(hinhHienTai, hinhCopy);
                    break;

                case 3: hinhCopy = new TamGiac(); Copy(hinhHienTai, hinhCopy);
                    break;

                case 4: hinhCopy = new DuongThang(); Copy(hinhHienTai, hinhCopy);
                    break;

                default: break;
                }


                pictureBox.Refresh();
            }
        }
コード例 #3
0
 private void Copy(HinhVe hinhHienTai, HinhVe hinhCopy)
 {
     hinhCopy.diemBatDau  = hinhHienTai.diemBatDau;
     hinhCopy.diemKetThuc = hinhHienTai.diemKetThuc;
     hinhCopy.khuVuc      = hinhHienTai.khuVuc;
     hinhCopy.mauVe       = hinhHienTai.mauVe;
     hinhCopy.doDamNet    = hinhHienTai.doDamNet;
 }
コード例 #4
0
 private void BtnxCut_Click(object sender, EventArgs e)
 {
     if (hinhHienTai != null && hinhHienTai.loaiHinh != 0)
     {
         hinhCopy = hinhHienTai;
         lHV.XoaHinhCuoi();
         lHV.listHinh.Remove(hinhHienTai);
         pictureBox.Refresh();
     }
 }
コード例 #5
0
 private void BtnxDelete_Click(object sender, EventArgs e)
 {
     if (hinhHienTai != null && hinhHienTai.loaiHinh == 0)
     {
         lHV.XoaHinhCuoi();
         lHV.listHinh.Remove(hinhHienTai);
         pictureBox.Refresh();
         hinhHienTai = null;
     }
     else if (hinhHienTai != null && hinhHienTai.loaiHinh != 0)
     {
         lHV.listHinh.Remove(hinhHienTai);
         pictureBox.Refresh();
         hinhHienTai = null;
     }
 }
コード例 #6
0
        public void KhoiTao()
        {
            lHV = new listHinhVe();

            hinhNenChim = new Bitmap(pictureBox.Width, pictureBox.Height, pictureBox.CreateGraphics()); //tạo 1 hình bitmap
            Graphics g = Graphics.FromImage(hinhNenChim);                                               //lấy đối tượng Graphics từ bitmap

            g.Clear(Color.White);                                                                       //xóa trắng bề mặt

            hinhNenNoi = new Bitmap(pictureBox.Width, pictureBox.Height, pictureBox.CreateGraphics());
            g          = Graphics.FromImage(hinhNenNoi);
            g.Clear(Color.White);

            penLevel = 1;
            mauVe    = Color.Black;
            doDamNet = 1;

            listButton.Add(btnColor1);
            listButton.Add(btnColor2);
            listButton.Add(btnColor3);
            listButton.Add(btnColor4);
            listButton.Add(btnColor5);
            listButton.Add(btnColor6);

            colorPicker.SelectedColor = Color.Black;

            listLabel.Add(lbl5);
            listLabel.Add(lbl4);
            listLabel.Add(lbl3);
            listLabel.Add(lbl2);
            listLabel.Add(lbl1);

            UpdatePen(penLevel, mauVe);

            lastBtnxID         = 0;          //ID của nút bấm
            btnxConTro.Enabled = false;

            isMoving = false;

            hinhCopy = null;

            IDhinhHienTai = 0;
            lHV.listHinh.Clear();

            pictureBox.Refresh();       //vẽ lại pictureBox-làm mới
        }
コード例 #7
0
        private void PictureBox_Mouse_Up(object sender, MouseEventArgs e)
        {
            if (hinhHienTai != null && hinhHienTai.loaiHinh == 0 && isMoving == false)
            {
                lHV.XoaHinhCuoi();
                pictureBox.Refresh();

                hinhHienTai = null;
            }
            if (hinhHienTai != null && isMoving == false)
            {
                lHV.listHinh.Insert(lHV.listHinh.Count, hinhHienTai);  //thêm hình mới vào list
                hinhHienTai.Mouse_Up(sender);
                hinhHienTai.VeKhung(pictureBox.CreateGraphics());
            }
            if (isMoving)
            {
                hinhHienTai.Mouse_Up(sender);
                pictureBox.Refresh();
                BtnxCircle_Click(btnxSizeMove, e);
                isMoving = false;
            }
        }
コード例 #8
0
 private void SubBtnXoaHinhCuoi_Click(object sender, EventArgs e)
 {
     lHV.XoaHinhCuoi();
     pictureBox.Refresh();
     hinhHienTai = null;
 }
コード例 #9
0
        private void PictureBox_Mouse_Move(object sender, MouseEventArgs e)
        {
            lblPosition.Text = "Vị trí chuột: (" + e.Location.X.ToString() + ", " + e.Location.Y.ToString() + ")";

            if (IDhinhHienTai == -1)  //nút "Vị trí và kích cỡ" đã được bấm
            {
                if (isMoving == false)
                {
                    for (int i = lHV.listHinh.ToArray().Length - 1; i >= 0; i--)        //kiểm tra từng hình xem hình nào bị...
                    {
                        int vt = (lHV.listHinh.ToArray())[i].KiemTraViTri(e.Location);
                        if (vt == 0)        //...chuột di chuyển trên bề mặt
                        {
                            hinhHienTai = (lHV.listHinh.ToArray())[i];
                            if (e.Button == MouseButtons.Left)      //=> sẽ di chuyển hình này
                            {
                                Cursor = Cursors.Hand;
                                hinhHienTai.diChuyen         = true;    //cho phép di chuyển
                                hinhHienTai.thayDoiKichThuoc = false;   //không cho phép thay đổi kích thước
                                isMoving = true;                        //bật cờ đang di chuyển



                                BtnxCircle_Click(btnxConTro, e);                  //mượn nút "Chuột" để di chuyển (bản thân nút "Vị trí và kích cỡ" sẽ không di chuyển hình
                                pictureBox.Refresh();
                                hinhHienTai.VeKhung(pictureBox.CreateGraphics()); //vẽ khung
                                lHV.listHinh.RemoveAt(i);                         //sau khi di chuyển sẽ phát sinh hình mới tại vị trí mới=>xóa hình cũ
                            }
                            else // chuột đi qua mà không bấm
                            {
                                isMoving             = false;
                                hinhHienTai.diChuyen = false;
                            }


                            Cursor = Cursors.Hand;
                            pictureBox.Refresh();
                            hinhHienTai.VeKhung(pictureBox.CreateGraphics());
                            break;
                        }
                        else if (vt > 0) //chuột chỉ đúng điểm điều khiển (1 trong 8 chấm vuông nhỏ làm khung)   => sẽ thay đổi kích thước hình này
                        {
                            hinhHienTai = (lHV.listHinh.ToArray())[i];
                            if (e.Button == MouseButtons.Left)
                            {
                                hinhHienTai.thayDoiKichThuoc = true;        //cho phép thay đổi kích thước
                                hinhHienTai.diChuyen         = false;       //không cho phép di chuyển
                                isMoving = true;


                                BtnxCircle_Click(btnxConTro, e);


                                pictureBox.Refresh();
                                hinhHienTai.VeHCNDiemDieuKhien(pictureBox.CreateGraphics(), 5);
                                lHV.listHinh.RemoveAt(i);
                            }
                            else
                            {
                                isMoving = false;
                                hinhHienTai.thayDoiKichThuoc = false;
                            }



                            Cursor = Cursors.Cross;
                            pictureBox.Refresh();
                            hinhHienTai.VeHCNDiemDieuKhien(pictureBox.CreateGraphics(), 5);
                            break;
                        }

                        else //tìm trong danh sách không có hình nào bị chuột đi qua
                        {
                            Cursor = Cursors.Default;
                        }
                    }
                }
            }
            else  //không phải nút "Vị trí và kích cỡ" => là nút vẽ hình hoặc nút "Chuột"
            {
                if (hinhHienTai != null)
                {
                    if (hinhHienTai.KiemTraViTri(e.Location) > 0)   //nếu chuột chỉ đúng 1 trong 8 chấm vuông nhỏ => đổi chuột thành hình dấu +
                    {
                        Cursor = Cursors.Cross;
                    }

                    else if (hinhHienTai.KiemTraViTri(e.Location) == 0)     //tương tự với lúc chuột nằm trong hình => chuột hình bàn tay
                    {
                        Cursor = Cursors.Hand;
                    }
                    else
                    {
                        Cursor = Cursors.Default;       //còn lại thì mặc định
                    }
                }

                if (e.Button == MouseButtons.Left)
                {
                    if (hinhHienTai != null)
                    {
                        hinhHienTai.Mouse_Move(e);
                        pictureBox.Refresh();
                        hinhHienTai.VeKhung(pictureBox.CreateGraphics());
                    }
                }
            }
        }