How to stop Visual Studio's Android emulator displaying off screen.

Martin Brown 31 Reputation points
2024-09-29T19:33:55.1+00:00

I'm trying to use Visual Studio 2022 Community Edition to develop a MAUI application for an Android phone. I use a laptop that is sometimes connected to an external monitor. When I'm not connected to an external monitor the Android Emulator that Visual Studio runs appears off screen. I don't seem to be able to get it back onto the screen.

I've tried updating visual studio and the Android SDK and tools to the latest versions with no joy.

I've tried leaving the emulator on the lap top screen when I shut down, but the issue recurs when I start the machine up again.

I've tried using Alt+<Space> M but that does not seem to work like it would do with most normal windows.

The only way I seem to be able to get the emulator back on screen to to plug in a second monitor and drag it from where it was onto the laptop screen then disconnect the monitor again. This doesn't work well when I'm on the train/plane and don't have a second monitor.

Does any one have any other tricks?

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
5,132 questions
.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,514 questions
0 comments No comments
{count} votes

Accepted answer
  1. Liqun Shen (Shanghai Wicresoft Co Ltd) 235 Reputation points Microsoft Vendor
    2024-09-30T07:07:49.7266667+00:00

    Hello,

     

    For the problem that the Android emulator will appear off-screen, you can follow the steps below to reset the coordinates of the emulator.

     

    Step 1. Open Android Device Manager in Visual Studio.

     

    Step 2. Select the Android emulator on Device Manager.

     

    Step 3. Click the ... button in the upper right corner of Device Manager and select Reveal in Explorer.

     

    Step 4. Open the emulator-user.ini file in the folder with a text editor, then change the value of window.x and window.y to 1 and save. After that, your emulator will be positioned in the upper left corner of the screen.

    In addition, Android Emulator isn't a Microsoft product. You could refer to the same issue in the Google Issue Tracker at https://issuetracker.google.com/issues/354482061

     

    Best Regards,

      


     

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

     

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

     

     

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Martin Brown 31 Reputation points
    2024-09-30T19:33:23.2633333+00:00

    Maybe not the easiest answer but it did work. I wrote this program that finds the window handle and moves it.

    using System.Runtime.InteropServices;
    using System.Text;
    
    class Program
    {
        private static List<string> windowTitles = new();
    
        private delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr lParam);
    
        [DllImport("user32.dll")]
        private static extern bool EnumWindows(EnumWindowsProc enumProc, IntPtr lParam);
    
        [DllImport("user32.dll")]
        private static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int count);
    
        [DllImport("user32.dll", SetLastError = true)]
        [return: MarshalAs(UnmanagedType.Bool)]
        private static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
    
        static void Main()
        {
            EnumWindows(EnumTheWindows, IntPtr.Zero);
        }
    
        private static bool EnumTheWindows(IntPtr hWnd, IntPtr lParam)
        {
            StringBuilder windowText = new StringBuilder(256);
            GetWindowText(hWnd, windowText, 256);
    
            if (windowText.ToString().StartsWith("Android Emulator"))
            {
                MoveWindow(hWnd, 0, 0, 800, 600, true);
            }
    
            return true;
        }
    }
    
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.