You can copy and paste code as text on the forum. Just place 3 tildes ~~~ on a line by themselves, directly above and directly below the code.
In terms of your question, you can change the window size at any point and it will respect the stretch mode and aspect ratio settings.
You don't need to alter anything at run time. If you don't know the resolution ahead of time (which you won't for a full screen game) then set stretch to 2D and aspect to either Keep or Expand.
If you know the game will only be played in landscape (if it is a PC game) then you select Keep Height, and if it's a mobile game that is portrait only, then you can do Keep Width.
In any case, the window will expand to the HTML Canvas size, so any resizing should be done in Javascript or, more usefully, CSS. That way it is dynamic and responsive.