R
rogersteph
Hello,
I'm trying to create a small program, where a user can draw a simple
line with the mouse. Imagine a signature application where you can
write your name with the mouse. Or a tablet. Just like in paint.
I've tried something like this:
private void pbMouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
this.shouldPaint = true;
}
}
private void pbMouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
shouldPaint = false;
}
}
private void pbMouseMove(object sender, MouseEventArgs e)
{
if (shouldPaint)
{
Graphics graph = pictureBox1.CreateGraphics();
Pen pen = new Pen(Color.Black);
graph.DrawRectangle(pen, e.X, e.Y, 1, 1);
graph.Dispose();
}
}
This works, however it's too slow. That is if you move the mouse fast
like you would do if you were writing lots of points are skipped and
it's not a solid line but some random dots.
I guess the MouseMove Event is not fired fast enough or it's not
possible to process so many events because the drawing operation takes
too much time.
Anyone could point me in the right direction?
Thanks
I'm trying to create a small program, where a user can draw a simple
line with the mouse. Imagine a signature application where you can
write your name with the mouse. Or a tablet. Just like in paint.
I've tried something like this:
private void pbMouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
this.shouldPaint = true;
}
}
private void pbMouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
shouldPaint = false;
}
}
private void pbMouseMove(object sender, MouseEventArgs e)
{
if (shouldPaint)
{
Graphics graph = pictureBox1.CreateGraphics();
Pen pen = new Pen(Color.Black);
graph.DrawRectangle(pen, e.X, e.Y, 1, 1);
graph.Dispose();
}
}
This works, however it's too slow. That is if you move the mouse fast
like you would do if you were writing lots of points are skipped and
it's not a solid line but some random dots.
I guess the MouseMove Event is not fired fast enough or it's not
possible to process so many events because the drawing operation takes
too much time.
Anyone could point me in the right direction?
Thanks