0

In top of form1 I did:

private int pixelscounter;
private int counter;
private float xFactor, yFactor;
List<PointF> points = new List<PointF>();
double increment = 1.25;
double factor = 1.0;
Image img;
private Point startingPoint = Point.Empty;
private Point movingPoint = Point.Empty;
private bool panning = false;
GraphicsPath gp = new GraphicsPath();
GraphicsPath redgp = new GraphicsPath();

Then in pictureBox1 move event I did:

if (checkBox2.Checked && e.Button == MouseButtons.Left)
{
    gp.AddLine(e.X * xFactor, e.Y * yFactor, e.X * xFactor, e.Y * yFactor);
    pixelscounter += 1;
    if (pixelscounter == 10)
    {
        redgp.AddEllipse((e.X) * xFactor, (e.Y) * yFactor, 3f, 3f);
        pixelscounter = 0;
    }
    p = e.Location;
    pictureBox2.Invalidate();
}

And the pictureBox2 paint event:

if (checkBox2.Checked)
{
    using (Pen pp = new Pen(Color.Green, 2f))
    {
        pp.StartCap = pp.EndCap = LineCap.Round;
        pp.LineJoin = LineJoin.Round;
        e.Graphics.DrawPath(pp, gp);
    }
    using (Pen pp = new Pen(Color.Red, 2f))
    {
        pp.StartCap = pp.EndCap = LineCap.Round;
        pp.LineJoin = LineJoin.Round;
        e.Graphics.DrawPath(pp, redgp);
    }
}

What I did is that when I click mouse left button press without leave it then drag the mouse around pictureBox1 its drawing a line in pictureBox2 in green and every 10 locations(pixels) its creating a red point automatic.

The problem is when I move the mouse fast or fast movements then the red points are not in the same distance of 10 locations(pixels) if I move the mouse very very slow the red points are too close to each other if I move the mouse regular more or less it seems that the points distance between each other are ok and if I move the mouse fast/very fast the distance between every red point is large more then 10 pixels.

How can I fix/solve this mouse movements problem ?

user3072062
  • 93
  • 1
  • 9

2 Answers2

1

You can calculate the difference between the start and the current position. Then draw a dot for every 10 pixels in between and set the new start position on the last dot you added.

This answer helps with calculating this path: https://stackoverflow.com/a/12550458/1277156

Community
  • 1
  • 1
Measurity
  • 1,316
  • 1
  • 12
  • 24
0

The mouse reports its position to the OS only so often. Typically, this rate is on the order of 100 times per second. That means for example in 1/10 sec, the mouse will report its position 10 times. So if you move the mouse quickly, say 120 pixels in 1/10 of a second, the reports will be roughly 12 pixels apart.

Some mouse drivers let you set the report rate. Fancy mice go up to 1000 times per second, but usually you can't go higher than around 200 per second. Unfortunately I don't know of any API that will let you change this setting easily from a program, but if you're targeting one particular mouse, you might have a chance.

I. J. Kennedy
  • 24,725
  • 16
  • 62
  • 87