Exemple #1
0
 public void RePaint(Cockroach c, PictureBox p)
 {
     if (check == false)
     {
         p.Bounds = new Rectangle(_x, _y, c.Image.Width, c.Image.Height);//создание новых границ изображения для PictureBox
         c.X      = _x;
         c.Y      = _y;
     }
     else
     {
         p.Bounds = new Rectangle(c.X, c.Y, c.Image.Width, c.Image.Height);
     }
     p.Image = c.Image;
 }
Exemple #2
0
 private void IMouseDown(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Left)
     {
         if (Form.ModifierKeys != Keys.Control)
         {
             ClearWorkItems();
         }
         int k = PB.IndexOf(sender as PictureBox); //запоминаем номер нажатого компонента PictureBox
         workpb        = sender as PictureBox;     //объявляем его рабочим
         workCockroach = LC[k];                    //по найденному номеру находим Таракана в списке
         if (!workField.Any())
         {
             workAction.Add(workCockroach);
             workField.Add(workpb);
         }
         else if (!workField.Contains(workpb))
         {
             workAction.Add(workCockroach);
             workField.Add(workpb);
         }
     }
     else if (e.Button == MouseButtons.Right)//cмена образа таракана нажатием ПКМ
     {
         ClearWorkItems();
         int        k      = PB.IndexOf(sender as PictureBox);
         PictureBox workpb = sender as PictureBox;
         _x = workpb.Location.X;
         _y = workpb.Location.Y;
         if ((LC[k].Image.Tag).ToString() == "1")
         {
             LC[k]           = new Cockroach(new Bitmap("cockroach1.png"));
             LC[k].Image.Tag = "2";
             // workpb.Location = new Point(_x,_y);
         }
         else
         {
             LC[k]           = new Cockroach(new Bitmap("cockroach.png"));
             LC[k].Image.Tag = "1";
             // workpb.Location=new Point(_x, _y);
         }
         check = false;
         workField.Add(workpb);
         workAction.Add(LC[k]);
         RePaint(LC[k], PB[k]);
     }
 }
Exemple #3
0
        private void NewHero_Click(object sender, EventArgs e)
        {
            int dx = rand.Next(Field.Width);
            int dy = rand.Next(Field.Height);

            cockroach           = new Cockroach(new Bitmap("cockroach.png"));
            cockroach.Image.Tag = "1";
            cockroach.newcoordinates(dx, dy);
            PictureBox p = new PictureBox();

            p.Location = new Point(dx, dy);
            Show(cockroach, p, Field);
            p.MouseMove += new MouseEventHandler(IMouseMove);
            p.MouseDown += new MouseEventHandler(IMouseDown);
            PB.Add(p);
            LC.Add(cockroach);
            workCockroach = cockroach;
            workpb        = p;
            ClearWorkItems();
            workField.Add(workpb);
            workAction.Add(workCockroach);
        }
Exemple #4
0
 public void Show(Cockroach c, PictureBox p, Panel owner)
 {
     check = true;
     RePaint(c, p);
     owner.Controls.Add(p);//добавляем PictureBox к элементу Panel
 }