Ejemplo n.º 1
0
        public void Show(Cockroach c, PictureBox p, Panel owner)
        {
            //c.X = (owner.Width - c.Image.Width) / 2;
            //c.Y = (owner.Height - c.Image.Height) / 2;

            RePaint(c, p);
            owner.Controls.Add(p);// добавляем PictureBox к элементу Panel
        }
Ejemplo n.º 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 (!workfields.Any())
                {
                    workbugs.Add(workCockroach);
                    workfields.Add(workpb);
                }
                else if (!workfields.Contains(workpb))
                {
                    workbugs.Add(workCockroach);
                    workfields.Add(workpb);
                }
            }
            else
            if (e.Button == MouseButtons.Right) // смена образа на пкм
            {
                ClearWorkItems();
                int k = PB.IndexOf(sender as PictureBox);
                workpb = sender as PictureBox;
                if ((LC[k].Image.Tag).ToString() == "1")
                {
                    LC[k]           = new Cockroach(new Bitmap("cockroach2.jpg"));
                    LC[k].Image.Tag = "2";
                }
                else
                {
                    LC[k]           = new Cockroach(new Bitmap("cockroach1.jpg"));
                    LC[k].Image.Tag = "1";
                }
                workfields.Add(workpb);
                workbugs.Add(LC[k]);
                RePaint(LC[k], PB[k]);
            }
        }
Ejemplo n.º 3
0
        private void NewBtn_Click(object sender, EventArgs e)
        {
            int dx = rnd.Next(Field.Width);
            int dy = rnd.Next(Field.Height);

            cockroach           = new Cockroach(new Bitmap("cockroach1.jpg"));
            cockroach.Image.Tag = "1";
            cockroach.newcoord(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();
            workfields.Add(workpb);
            workbugs.Add(workCockroach);
        }
Ejemplo n.º 4
0
 public void RePaint(Cockroach c, PictureBox p)
 {
     p.Bounds = new Rectangle(c.X, c.Y, c.Image.Width, c.Image.Height);//создание новых границ изображения для PictureBox
     p.Image  = c.Image;
 }