-2

I'm using C# visual studio with XNA and I would like to launch my game in maximized instead of fullscreen, and nothing found on google has worked yet...

I tried using:

Form form = (Form)Control.FromHandle(Window.Handle);
form.WindowState = FormWindowState.Maximized;

But even with the System.Windows.Forms.dll and System.Drawing.dll references, it doesn't work, tells me that Form doesn't exist.

Karl Gjertsen
  • 4,690
  • 8
  • 41
  • 64
Falquano
  • 11
  • 4

1 Answers1

0

Where have you put this code?

Have you set WindowState before InitializeComponent(), like this?

using System.Windows.Forms;

public Form() //Constructor
{
    var form = (Form)Form.FromHandle(Window.Handle);
    form.WindowState = FormWindowState.Maximized;
}
Karl Gjertsen
  • 4,690
  • 8
  • 41
  • 64
  • I put it in Initialize(), at the beginning. When I type your code, VS tells me that `WindowState`, `FormWindowState.Maximized` and `InitializeComponent()` doesn't exist in the current context. I am not sure I put the references in the right place, is it in "Namespace/References" or "NamespaceContent/References"? – Falquano Apr 07 '16 at 07:23
  • Sorry, code updated. Was your original code in the form constructor? – Karl Gjertsen Apr 07 '16 at 07:25
  • Have you looked at: http://stackoverflow.com/questions/11786640/how-to-maximize-window-in-xna – Karl Gjertsen Apr 07 '16 at 07:25
  • 1
    Ah, I just had to add `System.Windows.Forms.` before all the `Form`. That solves the problem! Thanks very much! – Falquano Apr 07 '16 at 07:26
  • Great! :-) I'll update my answer in case it helps someone else. – Karl Gjertsen Apr 07 '16 at 07:27