0

I'm currently making simple programs to draw line on picturebox. Click for the first point then drag & release for the 2nd point. Now I want to make that line can be edited rather than making new one. like when click & drag on the edge it will resized to the new drop point and when click & drag on the body it will move the entire item without changing the shape. the current picturebox code is like this

        public Form1()
        {
            InitializeComponent();
            pictureBox1.BackgroundImage = Image.FromFile("C:/Users/RPC1940/Pictures/500px.jpg");
            DrawArea = new Bitmap(pictureBox1.Size.Width, pictureBox1.Size.Height);
            pictureBox1.Image = DrawArea;
        }
        private void pictureBox1_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            Pen pen = new Pen(Color.Black, 3); 
            g.DrawLine(pen,x1,y1,x2,y2); 
            pen.Dispose();
            pictureBox1.Refresh();
            this.DoubleBuffered = true;
        }

and the current mouse click & drag to draw line is like this

        private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
        {
            if (drawRadio.Checked == true)
            {
                x1 = e.Location.X;
                y1 = e.Location.Y;
                x1Box.Text = x1.ToString();
                y1Box.Text = y1.ToString();
            }
            else if (editRadio1.Checked == true)
            {
                x1 = e.Location.X; 
                y1 = e.Location.Y; 
                x1Box.Text = x1.ToString(); 
                y1Box.Text = y1.ToString();
                pictureBox1.Refresh();
            }
            else if(editRadio2.Checked == true)
            {
                x2 = e.Location.X;
                y2 = e.Location.Y;
                x2Box.Text = x2.ToString();
                y2Box.Text = y2.ToString();
                pictureBox1.Refresh();
            }
        }
        private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
        {
            if(drawRadio.Checked == true)
            {
                x2 = e.Location.X; //Second x coordinate (mouse release)
                y2 = e.Location.Y; //Second y coordinate (mouse release)
                x2Box.Text = x2.ToString();
                y2Box.Text = y2.ToString();
            }
        }

Anyone know how to edit the lines that has drawn in the box by dragging the edge or body of it? Thank you very much

**Edit added few radio box. drawRadio is default to draw the line, editRadio1 & editRadio2 for edit the coordinates of point 1 & 2. there's 1 more radio box to move the etire line shape but I dont know how is it works yet. if anyone know please tell me. Thanks

  • You need a) a List of your points b) a [movable control](https://stackoverflow.com/questions/45423255/being-able-to-drag-around-dynamically-created-panels/45423971#45423971) to show a point to edit. c) code the mousemove to detect when mouse is over a point. OR add a mode to show all points.. – TaW Dec 13 '19 at 08:37
  • Check [How to drag and move shapes in C#](https://stackoverflow.com/questions/38747027/how-to-drag-and-move-shapes-in-c-sharp) and [Moving and selecting shapes](https://stackoverflow.com/questions/38345828/how-can-i-treat-the-circle-as-a-control-after-drawing-it-moving-and-selecting) –  Dec 13 '19 at 12:33

0 Answers0