psychogeek

Hello :)

My game has a windows forms front end to allow the user to configure how it runs, including the resolution settings. Being that they can drag this window between monitors on multi-monitor systems like mine, how can I tell what the SupportedDisplayModes are on the monitor(adapter) currently in use...before Game.Run()

This seems like it should be simple to do but the answer is eluding me.

TIA!


Re: XNA Framework Graphics Adapter - Multiple monitor support

dczraptor

Microsoft.Xna.Framework.Graphics.GraphicsAdapter.Adapters for all the adapters. GraphicsAdapter.DefaultAdapter for the default one.






Re: XNA Framework Graphics Adapter - Multiple monitor support

psychogeek

Those properties are obvious :)  However, they don't tell me what I need to know...that is: which adapter my application is currently running on.  It may not always be the DefaultAdapter.

Picture this:
User starts my game which opens a normal Windows Form (initially).
User drags the form to their second monitor (which has its own adapter)
User clicks "Play game" expecting the game to play on that monitor...not the first one.

To support the above, I need to know the SupportedDisplayModes of the adapter that the second monitor is using...not the first one.  Sure I can iterate through all the adapters...but I don't see a method that tells me which one is in use.





Re: XNA Framework Graphics Adapter - Multiple monitor support

psychogeek

After a little bit of research I developed this function which will tell you what adapter the current windows form is running on:

private GraphicsAdapter GetCurrentAdapter()
{
    Screen scr = Screen.FromHandle(this.Handle);

    // Trim the device name
    string currentdevice = scr.DeviceName;
    int pos = scr.DeviceName.IndexOf('\0');
    if (pos != -1)
    {
        currentdevice = scr.DeviceName.Substring(0, pos);
    }

    // Find the matching adapter
    foreach (GraphicsAdapter ga in GraphicsAdapter.Adapters)
    {
        if (ga.DeviceName == currentdevice)
        {
            return ga;
        }
    }
    return GraphicsAdapter.DefaultAdapter;
}