0

enter image description hereI'm trying to create a drawing app that uses an image stored in the resources as a paintbrush The drawing will be depened on the location of the mouse and the mouse movement event The problem is when drawing quickly, there are spaces between an images of the drawing, as in the picture enter image description here the code of application

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace drawing_using_image
{
    public partial class Form1 : Form
    {
        private Image image;
        private Bitmap bm;
        private Point ploc;
        private Rectangle rec;
        private bool ismouddown=false;

        public Form1()
        {
            InitializeComponent();
            image = Properties.Resources.angle45;
            bm = new Bitmap(image, image.Width, image.Height);
        }

        private void panel1_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                ploc = e.Location;
                Graphics g = panel1.CreateGraphics();
                rec = new Rectangle(ploc.X, ploc.Y, 45, 45);
                Pen p = new Pen(Color.Black, 1);
                g.DrawImage(image, rec);   
            }
        }

        private void panel1_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                ismouddown = true;
            }
        }
    }
}
Son of Man
  • 1,213
  • 2
  • 7
  • 27
  • 2
    This is going to depend on the mouse reporting rate. You should remember the last mouse position in `panel1_MouseMove()` so that it can compare previous and current positions in order to know what to draw between the positions. Also, you really need to do all your drawing in` Paint` - otherwise it will disappear if you (for example) minimise and restore your application. – Matthew Watson May 25 '23 at 08:45
  • can you explain that by code ? i main about mouse reporting rate and las position – Hassn shalabi May 25 '23 at 10:45
  • 1
    Have a look at this: https://stackoverflow.com/questions/4164864/what-is-the-proper-way-to-draw-a-line-with-mouse-in-c-sharp – Matthew Watson May 25 '23 at 10:58

0 Answers0