How can I get a relative position to my Canvas when the mouse is outside of the application Window in WPF

147 Views Asked by At
public MainWindow()
{
        InitializeComponent();
        _hook = Hook.GlobalEvents();
        _hook.MouseMove += DrawMouseMove;
}
private void DrawMouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{

        Point GetMousePos() => Mouse.GetPosition(DrawCanvas);
        Point pos = GetMousePos();
        CoordinateLabel.Content = $"{Math.Ceiling(pos.X)}, {Math.Ceiling(pos.Y)}px";

        //... code down here is draw a shape with pos, a relative position to DrawCanvas 

}

I'm using hook for global event, but i stuck at getting relative position to DrawCanvas when the mouse is outside of my application window. The thing I want to achive is just like mspaint, you can still draw shape even when the mouse moved out of the window

0

There are 0 best solutions below