简体   繁体   中英

Drawing line on Canvas using WPF

In my WPF program I'm using canvas as a place to render drawings so when it is in line-drawing mode any unfinished line follows mouse cursor and waiting for another click to find the ending point of line.

One visual problem is that most of the time lines doesn't follow the cursor super fast... even sometimes I can see there is a delay. It finds it anyway but it doesn't stick to moving cursor as it is done in other drawing applications eg autocad or soildworks ...

What am I missing here?

Thanks,

As @PeteBaughman said, it would help to know a bit more about your code, trying posting a sample of how you add and edit the line. One possible solution though, is, if you haven't already done so, trying capturing the mouse:

XAML:

<Canvas OnMouseDown="MyCanvas_MouseDown" ... />

Code-Behind:

public void MyCanvas_MouseDown(object sender, MouseButtonEventArgs e){
    MyCanvas.CaptureMouse();
}

This should ensure you're getting all the mouse events and was the solution to a very similar problem I recently had.

Regards,

Richard

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM