I am trying to figure out how to write the code so the response time between the mouse movement and line drawing is instant. Everytime I do this there is always lag between the 2. I have coded this in the windows forms and now I am coding it in WPF.
The problem definitly lies in the code and is not my computer.
Basicaly it works like this. Click anywhere and point1 is created. Move the mouse and point2 is updated and a line is drawn from Point1 to Point2 which changes on mouse movement.
below is my extremly simple code to do this.. It may seem instant but if you maximize the window and make the line long and move the mouse quickly, you can notice it more easily..
Also, there will be an image layer under this in the future which for sure will cause it to lag even more.. But right now I just want to optimize this.
When I used other such programs from 5+ years ago, the line movement was actually instant. Thats why I am confused as to why with this newer coding, its laggy..
Point mLoc;
Line myLine = new Line();
public MainWindow()
{
InitializeComponent();
SnapsToDevicePixels = false;
myLine.Stroke = System.Windows.Media.Brushes.White;
myLine.StrokeThickness = 1;
canvas1.Children.Add(myLine);
}
private void onMMove(object sender, MouseEventArgs e)
{
mLoc = Mouse.GetPosition(canvas1);
myLine.X2 = mLoc.X;
myLine.Y2 = mLoc.Y;
}
private void onMLClick(object sender, MouseButtonEventArgs e)
{
mLoc = Mouse.GetPosition(canvas1);
myLine.X1 = mLoc.X;
myLine.Y1 = mLoc.Y;
}