1 year ago
#36284
itsncnt
How can I get a relative position to my Canvas when the mouse is outside of the application Window in WPF
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
c#
wpf
hook
mouse-hook
0 Answers
Your Answer