How to manually fire a MouseMove event for a stationary mouse

I am reading the "value under the cursor" for the contents of the chart. I am currently achieving this using ReactiveExtensions and subscribing to the GetMouseMove event in my Grid chart background:

private void SetupMouseover( Grid plotArea)
{
    var mouseMove = from mo in plotArea.GetMouseMove()
                        select new
                        {
                            CurrentPos = mo.EventArgs.GetPosition( plotArea )
                        };

    mouseMove.Subscribe(
        item =>
        {
            // Update the readout contents
            readoutTextBlock.Text = PositionToReadoutValue(item.CurrentPos);
        }
    );
}

And it works great. I can move the mouse and I am updating my text block.

The problem is that the contents of the chart are dynamically updated (move around the screen). If I left the mouse cursor still above the point, the content below it will change, but (obviously) the reading will not be updated.

I tried to manually start moving the mouse, setting the cursor position on myself whenever the data in the model was updated:

private void MoveCursor()
{
    // move the mouse cursor 0 pixels
    System.Windows.Forms.Cursor.Position = new System.Drawing.Point(System.Windows.Forms.Cursor.Position.X, 
                                                                    System.Windows.Forms.Cursor.Position.Y);    
}

. (X-1, Y-1) DID , ( X + 1, Y + 1), mousemove .

readoutTextBlock , Mouse.GetPosition(m_PlotArea), ( ), m_PlotArea.

?

+3
1

, , .

IObservable<Position> mouseMove = GetMouseMove(); // stream of MouseMove events

IObservable<Position> manualTrigger = new Subject<Position>();

var positionChange = mouseMove.Merge(manualTrigger);
positionChange.Subscribe(pos => ...);

:

manualTrigger.OnNext(new Position(...)); 
+2

Source: https://habr.com/ru/post/1761855/


All Articles