0

I have a project for uni which is to make Paint. The part that i can't do is the cut, copy, paste. The user is drawing in a PicureBox and in the PicuteBox MouseDown,Move,Up events is the code which allows the user to draw. If i try to put a code for rubber band box in these events it doesn't work. I tried creating a selection item in the MenuStrip i use and use the selection MouseMove,Down,Up events, but it doesn't work. The user should be able to draw something or upload a picture and when he press that selection button to mark the part of the drawing or the picture he wants to cut, copy or paste. I'm still a beginner, so sorry if my question is not well explained or the code is not correct.

  public partial class Form1 : Form
{

    int x = -1;
    int y = -1;

    Graphics g;
    Pen pen;
    public Form1()
    {
        InitializeComponent();
        g = pictureBox1.CreateGraphics();
        pen = new Pen(Color.Black, 5);

    }
    private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
    {
        startPaint = true;
        x = e.X;
        y = e.Y;


    }

    private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
    {
        if (startPaint && x != -1 && y != -1)
        {
            g.DrawLine(pen, new Point(x, y), e.Location);
            x = e.X;
            y = e.Y;
        }


    }



    private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
    {
        startPaint = false;
        x = -1;
        y = -1;

    }
Viv
  • 1
  • 1
  • 1
  • Do not try to draw inside your `MouseMove` handler; that will get overwritten the next time your `PictureBox` is redrawn. Instead, store the mouse coordinates and [draw your box in the `Paint` event handler](https://stackoverflow.com/a/50071046/22437). – Dour High Arch Mar 08 '20 at 17:27
  • Two of the many: see the notes and the magnifying Lens definition [here](https://stackoverflow.com/a/56128394/7444103), and [a simple example](https://stackoverflow.com/a/53708936/7444103), to create and preserve selections. – Jimi Mar 08 '20 at 17:40
  • 1
    [Examples](https://stackoverflow.com/search?q=user%3A3152130+rubber+band+) – TaW Mar 08 '20 at 18:20
  • @Dour: A rubberband is not __supposed__ to persist (while being drawn)! – TaW Mar 08 '20 at 18:21

0 Answers0