Member 13594414 Ответов: 1

Как переместить группу прямоугольников вместе с помощью мыши в C#?


Эй ,
Я рисую на растровых изображениях ,в чертежи я включил только прямоугольники . Я хочу переместить все мои прямоугольники вместе как группу . Может ли кто-нибудь помочь мне в этом вопросе ?

Что я уже пробовал:

String data = "";
            Font font = new Font("Arial", 14);
         
            Rectangle rect = new Rectangle();
            rect.Size = new Size(280, 190);
            for (int x = 0; x < 1; x++)
            {

                rect.X = x * (rect.Width + 45) + 380;
                for (int y = 0; y < 1; y++)
                {
                    rect.Y = y * (rect.Height + 35) + 25;
                    listRec.Add(rect);
                    data = rect.ToString();
                    TextWriter txt = new StreamWriter("E:\\Blisters.txt", true);
                    txt.WriteLine(data);
                    txt.Close();
                }
            }

            foreach (Rectangle rec in listRec)
            {
                g = pictureBox1.CreateGraphics();
                Pen p = new Pen(Color.Red, 3);
                g.DrawRectangle(p, rec);
               // g.DrawString("B1", font, new SolidBrush(Color.Yellow), 55, 25);
                g.DrawString("B2", font, new SolidBrush(Color.Yellow), (rect.Width + 40) + 60, 25);

            }
            //    String data;
            //Font font = new Font("Arial", 14);
            //Rectangle rect = new Rectangle();
            rect.Size = new Size(40, 65);
            for (int x = 0; x < 3; x++)
            {
                // rect.X = x * rect.Width;
                rect.X = x * (rect.Width + 30) + 463;
                for (int y = 0; y < 2; y++)
                {
                    rect.Y = y * (rect.Height + 35) + 38;
                    listRec.Add(rect);
                    data = rect.ToString();
                    TextWriter txt = new StreamWriter("E:\\B2Pockets.txt", true);
                    txt.WriteLine(data);
                    txt.Close();
                }
            }


            foreach (Rectangle rec in listRec)
            {
                g = pictureBox1.CreateGraphics();
                Pen p = new Pen(Color.Red, 3);
                g.DrawRectangle(p, rec);
                g.DrawString("p1", font, new SolidBrush(Color.Yellow), (rect.Width + 420), 35);
                g.DrawString("p2", font, new SolidBrush(Color.Yellow), (rect.Width + 40) + 450, 35);
                g.DrawString("p3", font, new SolidBrush(Color.Yellow), (rect.Width + 40) + 520, 35);
                g.DrawString("p4", font, new SolidBrush(Color.Yellow), (rect.Width + 420), (rect.Height + 30) + 40);
                g.DrawString("p5", font, new SolidBrush(Color.Yellow), (rect.Width + 40) + 450, (rect.Height + 30) + 40);
                g.DrawString("p6", font, new SolidBrush(Color.Yellow), (rect.Width + 40) + 520, (rect.Height + 30) + 40);
            }

Я уже пробовал вышеприведенный код.Прямоугольники нарисованы успешно. Но они не могут двигаться.

1 Ответов

Рейтинг:
2

#realJSOP

Эти статьи могут быть полезны:

Управление нарисованными фигурами в C#[^]