Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Creating A Loop With A Delay In A WPF Application. My App Gets The Mouse Position And Changes Element Text In The WPF App To

Creating A Loop With A Delay In A WPF Application. My App Gets The Mouse Position And Changes Element Text In The WPF App To Show The Current Mouse Position. This Works, But It Only Shows The Position On Load, It Does Not Change While Moving The Mouse. I Tried To Put It In A While (True) Loop With A Delay Of 1000ms, But Having A While Loop In The

Creating a loop with a delay in a WPF Application.

My app gets the mouse position and changes element text in the WPF app to show the current mouse position. This works, but it only shows the position on load, it does not change while moving the mouse. I tried to put it in a while (true) loop with a delay of 1000ms, but having a while loop in the MainWindow() function made the window not open at all. How do I update the mouse position text every second, or 0.5 seconds on the Main Window?

Here is the code I have:

namespace WpfApp1 { public partial class MainWindow : Window { [DllImport(\"user32.dll\")] static extern bool GetCursorPos(out System.Drawing.Point lpPoint);

public MainWindow() { InitializeComponent();

System.Drawing.Point p; if (GetCursorPos(out p)) { MouseX.Text = p.X.ToString(); MouseY.Text = p.Y.ToString(); } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Android 4 Application Development

Authors: Reto Meier

3rd Edition

1118223853, 9781118223857

More Books

Students also viewed these Programming questions

Question

What is a deposit in transit?

Answered: 1 week ago