Question

I am currently using the following code to allow the user to resize and maximize the window:

Window.AllowUserResizing = true; 
Window.ClientSizeChanged += Window_ClientSizeChanged; 

with the Window_ClientSizeChanged event handling the changes and re-scaling the drawn images etc.

This allows me to resize the window however much I want and also maximize it using the standard button in the window's handle. I would like to be able to start the application with the window in its maximized mode but can't figure out how to do so. I know I can use graphics.IsFullScreen = true; to show it in full screen mode but I would like to be able to run the program in a maximized, windowed mode. Any ideas?

Était-ce utile?

La solution

You can put this code in the constructor to do what you want:

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

This requires that you add a reference to System.Windows.Forms to your project.

This does have the downside that it actually sets up the graphics device twice on startup. Once in the normal way, and then once again because the window was resized. (Although this all happens before the form is first displayed.)

It has the advantage of being extremely simple to implement.


I'm going to poke around for awhile and see if the initialisation order can be changed...

There really is no simple way to get around this problem, it would seem.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top