C#: How to make a form remember its Bounds and WindowState (Taking dual monitor setups into account)

前端 未结 4 858
说谎
说谎 2020-12-15 10:51

I have made a class which a form can inherit from and it handles form Location, Size and State. And it works nicely. Except for one thing:

When you maximize the app

4条回答
  •  星月不相逢
    2020-12-15 11:51

    Try to spawn your main form in its saved location in restored (non-maximized) state, THEN maximize it if the last state was maximized.

    As Stu said, be careful about removed monitors in this case. Since the saved location may contain off-screen coordinates (even negative ones), you may effectively end up with and invisible (off-screen, actually) window. I think checking for desktop bounds before loading previous state should prevent this.

提交回复
热议问题