1
\$\begingroup\$

I have found a way to simply make an XNA 4.0 game's window borderless. Here is the code from the article:

IntPtr hWnd = this.Window.Handle;
var control = System.Windows.Forms.Control.FromHandle( hWnd );
var form = control.FindForm();
form.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
form.WindowState = System.Windows.Forms.FormWindowState.Maximized;

You add it to the Game's constructor and it works perfectly. I tested it on several Windows PCs and it's great: the game runs seemingly in full screen, even if you set the game's resolution lower/higher than your desktop one. The only issue I had with it is the fact that you need to provide positions for XNA's SpriteBatch methods (Draw and DrawString) in desktop resolution, not in game's resolution, while retrieving width/height from GraphicsDevice gives you the latter.

At the same time, DOTA 2 has borderless window option, but the game scales the window down, if your requested in-game resolution is lower than your desktop one. I wonder if they have a good reason for doing this?

I wanted to ask if this approach is safe to use on PC or can it be buggy occasionally? I would especially like to know if it will work with Windows XP as I don't have a pc with this system to test it.

\$\endgroup\$
  • 1
    \$\begingroup\$ I don't use XNA, but that's the way to do it in plain Direct3D (both pre-9 and 10+). However, XP is no longer supported: you might want to consider not including XP support to your game, as it creates an additional testing burden, and most people who play games are using 7 or newer anyways... (this statistic I just pulled out of nowhere, feel free to disagree) \$\endgroup\$ – Panda Pajama Sep 11 '14 at 9:30
  • \$\begingroup\$ Thanks @PandaPajama, is there a way in C# to test what system is installed on the client's PC? That way I would be able to lock this option for XP users. \$\endgroup\$ – cubrman Sep 11 '14 at 10:41
  • 1
    \$\begingroup\$ Mostly System.Environment.OSVersion, but that's outside the scope of this question. Google is your friend. However, disabling something because you suppose that it might not work on XP (it most likely will though) may be a bit overkill. If you really need to support XP, you should probably actually support it. If you're just being halfhearted about XP support, you might want to consider simply not supporting it. \$\endgroup\$ – Panda Pajama Sep 11 '14 at 11:02
  • 1
    \$\begingroup\$ Why would you need this functionality in the first place? \$\endgroup\$ – Petr Abdulin Sep 11 '14 at 11:09
  • \$\begingroup\$ @PetrAbdulin borderless window is a pretty badass feature as it looks like fullscreen mode and folds/unfolds as fast as in windowed mode. \$\endgroup\$ – cubrman Sep 11 '14 at 14:31
1
\$\begingroup\$
form.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
form.WindowState = System.Windows.Forms.FormWindowState.Maximized;

The MSDN documentation does a good job of listing the platforms supported for each function.

form.FormBorderStyle MSDN Documentation

Platforms

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

form.WindowState MSDN Documentation

Platforms

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

\$\endgroup\$
  • \$\begingroup\$ Looks like the answer was not trivial, I did not know MSDN lists versions for each function, thanks! \$\endgroup\$ – cubrman Sep 11 '14 at 18:26
  • \$\begingroup\$ This platforms list is for .NET 4.5, it's not relevant to XNA. \$\endgroup\$ – Petr Abdulin Sep 12 '14 at 1:59
1
\$\begingroup\$

Since this is a basic function, it should be safe, but you should look into setting up a VM or finding a friend with an XP machine so that you can specifically test for it.

\$\endgroup\$
0
\$\begingroup\$

This functionality is pretty basic for Win32 API, you are pretty safe to use it on XP (and even below).

The OS support for FormBorderStyle enumeration (on .NET 3.5), for example:

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC

same goes for FormWindowState. I hope that edit makes answer more useful.

\$\endgroup\$
  • \$\begingroup\$ Note, some people have flagged this for content and length issues. [sarcasm]You should add surplus text to say the same thing in more words because yeah.[/sarcasm] (On a more serious note, I don't know if the answer is correct, but I know it's a valid answer, I don't find its length to be an issue.) \$\endgroup\$ – user15805 Sep 11 '14 at 13:13
  • \$\begingroup\$ I would add: [sarcasm]you should add surplus text because f**k yeah![/sarcasm] \$\endgroup\$ – cubrman Sep 11 '14 at 14:29
  • 1
    \$\begingroup\$ I would assume people flagged it because "Yeah I think you're good" is a poor answer. \$\endgroup\$ – ClassicThunder Sep 11 '14 at 16:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.