# In XNA, how do I get forms to display in front of my full-screen game?

I'm trying to open a form in front of my game, which is full-screen. However, the form seems to appear only behind the game window.

At the moment, I'm doing this:

protected override void Update(GameTime gameTime)
{
if(Keyboard.GetState().IsKeyDown(Keys.Q))
{
graphics.IsFullScreen = true;
graphics.ApplyChanges();
new Form1().Show();
// The form is empty, just created.
}
base.Update(gameTime);
}


I can reach the form with AltTab, but this is unfriendly to the user.

How can I do this correctly?

• How are you exactly using forms with xna? You need to give more information or else this question is getting closed. As it is now, its impossible to give answer.
– Katu
Dec 10, 2015 at 10:13
– cat
Dec 10, 2015 at 10:38
• Forms are not supported in XNA. You can render XNA into a form control, however, that is also not supported and is pretty hackish. Going into full screen and still displaying the form? No that will not work. Dec 10, 2015 at 11:43
• well it was last chance, huh, drawed forms some difficult but if i need it i'll gotta do it. Thank you, so.
– cat
Dec 10, 2015 at 11:47
• Check out.. xnacontrols.codeplex.com Dec 10, 2015 at 11:48

Here is the solution for you: (which I use myself)

Form form = new Form();

form.SetBounds(100, 100, 800, 600);
form.TopMost = true;
form.Text = "Title";

//OR


## EDIT :

This is my method, which I use to make my game fullscreen. I find this method better than graphics.IsFullScreen.

[DllImport("USER32.DLL", CharSet = CharSet.Unicode)]
public static extern IntPtr FindWindow(String className, String windowName);

[DllImport("user32.dll", SetLastError = true)]
static extern void SwitchToThisWindow(IntPtr hWnd, bool turnOn);

System.Windows.Form gameForm;

protected override void Initialize()
{
/* ------ OPTIONAL ------ */
graphics.PreferredBackBufferWidth = 1280;
graphics.PreferredBackBufferHeight = 720;
graphics.PreferMultiSampling = false;
graphics.ApplyChanges();
/* ---------------------- */

System.Windows.Forms.Application.EnableVisualStyles();
gameForm = (System.Windows.Forms.Form)System.Windows.Forms.Form.FromHandle(Window.Handle);
gameForm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
//gameForm.TopMost = true;
gameForm.WindowState = System.Windows.Forms.FormWindowState.Maximized;
gameForm.Bounds = System.Windows.Forms.Screen.PrimaryScreen.Bounds;
gameForm.GotFocus += new EventHandler(gameForm_GotFocus);
base.Initialize();
}

void gameForm_GotFocus(object sender, EventArgs e)
{
gameForm.WindowState = System.Windows.Forms.FormWindowState.Maximized;
gameForm.Bounds = System.Windows.Forms.Screen.PrimaryScreen.Bounds;
}

{
//...
gameForm.Focus();
gameForm.BringToFront();
SwitchToThisWindow(gameForm.Handle, true);
}

• It doesn't hide XNA form Dec 10, 2015 at 14:58
• well i was tested wrong code. This one seems working normally. You're the best.
– cat
Dec 10, 2015 at 15:00
• It should be noted that the technique described here for full screen is commonly referred to as "Windowed Fullscreen", and can cause worsened performance in some cases. Just something to keep in mind. Dec 14, 2015 at 16:30

you need real full-screen? many games have 3 options:

1. windowed
2. fullscreen
3. fullscreen-windowed

the last is very simple, just create a winforms window without border and stretch it to the whole size of the screen.

WinForms are not supported in XNA. You can render XNA into a form control, however, that is also not supported, however it can work.

The better option, is to use a library that provides form controls from inside of XNA. Check out http://www.xnacontrols.codeplex.com

Or you can always write your own.

• Not Supported ???? Dec 10, 2015 at 14:57