I've created a windows forms application that allows the user to paint/draw on a panel. I've been trying to retrieve the mouse or cursor positions (x, y) relative to the panel while the user is moving the mouse, and store these into an array or list. So when the MouseDown event is triggered, the current mouse position is stored into the first index of the array, and as MouseMove is occurring, the rest of the cursor (X, Y) positions are stored, until MouseUp happens. This is a snippet of my code in the relevant parts of this question:
List<double> mousePosX = new List<double>();
List<double> mousePosY = new List<double>();
bool shouldPaint = false;
private void Painter_MouseDown(object sender, MouseEventArgs e)
{
if(e.Button == MouseButton.Left)
{
shouldPaint = true;
}
}
protected void Painter_MouseMove(object sender, MouseEventArgs e)
{
if(shouldPaint)
{
Graphics graphics = CreateGraphics();
graphics.FillEllipse(new SolidBrush(Color.FromName(colorvar)), e.X, e.Y, brushSize, brushSize);
mousePosX.Add(MousePosition.X);
mousePosY.Add(MousePosition.Y);
}
}
private void Painter_MouseUp(object sender, MouseEventArgs e)
{
if(e.Button == MouseButton.Left)
{
shouldPaint = false;
}
}
The issue I have is that my list is empty. Any suggestions?