wpf - Hide cursor when idle -
in wpf app, want hide cursor when hasn't moved number of seconds. if moved, want show again. ideas?
you use mousemove
event :
tested code:
mytimer = new timer(3000); mytimer.autoreset = false; mytimer.elapsed += delegate { mouseext.safeoverridecursor(cursors.none); }; //hide cursor private void myview_mousemove(object sender, mouseeventargs e) { mytimer.stop(); mouse.overridecursor = null; //show cursor mytimer.start(); }
this helper dispatching call override cursor:
public static class mouseext { public static void safeoverridecursor(cursor cursor) { application.current.dispatcher.invoke(new action(() => { mouse.overridecursor = cursor; })); } }
when timer elapses cursor hidden. when moved reappears , timer reset.
Comments
Post a Comment