leocb / MaterialSkin

Theming .NET WinForms, C# or VB.Net, to Google's Material Design Principles.
MIT License
438 stars 132 forks source link

Strange position of window when minimize #272

Closed valimaties closed 2 years ago

valimaties commented 2 years ago

Hi, If I store form's position and size when I minimize it, then strange values are stored. I think the same thing will happening if I will store the form's position and size if I will maximize form, it will not store the "real" size, or pozition.

StrangePosition

I think the values of Top, Left, Width, Height, must be the values before Maximize/Minimize action. So, could you do something to store those values?! As a workaround, I will check for what I will do with form before saving position and size. If it is Minimized, I will not save Top and Left, and if it is Maximized, I will not save the values of Width and Height. I must preserve those values as they are before.

VolatilePulse commented 2 years ago

Are you looking for the Rectangle provided by RestoreBounds. It's unusual to obtain the location of a form when it is minimized. How are you obtaining those values? When are you obtaining those values?

valimaties commented 2 years ago

Are you looking for the Rectangle provided by RestoreBounds. It's unusual to obtain the location of a form when it is minimized. How are you obtaining those values? When are you obtaining those values?

Hi @VolatilePulse, IMO, the location of form, before minimize or maximize, is the last position known before those actions.

Edit: Yes, I think I must change my approach and to keep RestoreBounds values. Thank you @VolatilePulse Edit2: RestoreBounds store the position and size of form at launch. It doesn't change when form changes size or location, so I don't think anymore that RestoreBounds is a solution. I've Re-Opened this issue.

VolatilePulse commented 2 years ago

I had another look at this today. RestoreBounds is designed to store the position of the window, but it is only updated prior to being maximized or minimized. The current location and size can be derived from Size and Location. However, minimized windows don't set the location and size like you'd expect. Windows effectively draws the windows off screen. You can check the WindowState to determine which properties you want to record.

If this solution doesn't work, you'll need to explain specifically what you're looking for so I can help provide a better solution.

valimaties commented 2 years ago

... You can check the WindowState to determine which properties you want to record.

Yes, seems that is the solution for my problem, saving window size, location and state. Thanks!