Mouse position in fullscreen app

When i create Monogame Windows Project and initialize screen with this settings:

graphics.PreferredBackBufferWidth = 1280;
graphics.PreferredBackBufferHeight = 720;
graphics.IsFullScreen = true;

with native resolution of 19201080 i get fullscreen app with 1280720 resolution but there is a moment that mouse can go beyond screen (Maximum mouse coordinates is 19191079). In CrossPlatform Desktop Project mouse cursor can’t get beyond screen (maximum coordinates is 1279719).
How can i handle this in Windows Project?

Mouse position is always between 0, 0 and the native resolution of your monitor, regardless of what buffer size you have set. So the code looks like this (I am using a virtual resolution as my game is designed for 1920x1200, so I am scaling up or down everything depending on the actual resollution):

MouseState mouseState = Mouse.GetState();
Point MousePosition = mouseState.Position;
//the bottom right value is 1919, 1079 at this point.


Vector2 TargetResolutionScale = new Vector2
   graphics.PreferredBackBufferWidth * 1.0f / VIRTUAL_RESOLUTION_WIDTH,
   graphics.PreferredBackBufferHeight * 1.0f / VIRTUAL_RESOLUTION_HEIGHT

  if (isFullscreen)
   MousePosition = new Point(
   (int)(MousePosition.X * TargetResolutionScale.X),
   (int)(MousePosition.Y * TargetResolutionScale.Y));
   //the bottom right is now 1279, 719

This was just some code snippet to give you some clue, of course this is not how it really looks like in my game.

However, there is one small bug that I experienced, so I need to find a proper workaround for it:
When the game is running in windowed mode, if the resolution is the same as your native resolution and the window is not borderless (so you can see the title, the close button and the rest of the window), the 0,0 position will be the actual rendering window’s 0,0 position, but the mouse’s 0,0 will be the monitor’s 0,0 so there is a small calculation error in the above code. I think I need to check this specific case as add some to the x and y of the final mouse postion.

Thanks! In that case a can get proper mouse coordinates, but still if i set

IsMouseVisible = true

native mouse cursor can still go beyound screen. In that case i can check if raw coordinates of mouse cursor is higher
than setted screen width and heigh and set new coordinates.

I can see no problem with mouse position outside of the window. Your controls should handle IsMouseOver state by their own and if you create a MouseHelper class like I did, you can trace relative position changing (e.g. “going right” is true even from 0 to 1 and 3578 to 3579). Simply store the previous mouse state, compare the necessary values, at the end of the update of the mouse state overwrite the previous state with the current state, and jobs done. You do not even need to know the actual value of the mouse position, simply you can do something like this:

MouseState PreviousMouseState { get; set; }
MouseState CurrentMouseState { get; set; }

bool GoingRight { get; set; }

public void Update(GameTime gameTime)
   CurrentMouseState = Mouse.GetState();

   GoingRight = (PreviousMouseState != null)
      ? (PreviousMouseState.Position.X < CurrentMouseState.Position.X)
      : false;

   PreviousMouseState = CurrentMouseState;

Hope that helps!