Unfortunately there isn't a "simpler" way.
You're right in thinking that it is "hacky". It depends on internal implementation details of XNA. Which means it could break in future versions of XNA (there's nothing saying that XNA's Game
class needs to use a Form
). Also - in theory it might fail in unexpected ways - the XNA team hasn't necessarily tested this behaviour at all - let alone extensively.
(Note that XNA games are version-specific. For example: An XNA 3 game requires XNA 3 and won't run on XNA 4. So your binary is pretty safe against framework updates - but not necessaraly your code.)
There is a non-hacky way, by creating your own alternative to the Game
class. The WinForms sample shows you how. But then you lose all the helpful stuff that Game
and its friends provides (most notably the timing stuff).
But - because this is such a trivial settings change, it's probably completely safe to do in this case. And worth the risk, given the alternative is much trickier to implement. Maybe you could add some error-checking/exception handling - but even that's probably not necessary for this specific case.
I'm pretty sure XNA won't care if the FormBorderStyle
changes out from under it.
(Of course, I've seen people pulling out the Form
and doing some extremely brazen things with it. If you need to do anything beyond tweaking a few settings - I recommend going the "WinForms Sample" route.)