I have a main form. Using the KeyDown event I've been able to make the form go Full Screen at the user's request (by pressing CTRL + ALT + ENTER).
So, I need: 1) when the form is not at "Full Screen mode" and the user presses CTRL + ALT + ENTER, as expected, the form goes Full Screen, and 2) when the form is already at "Full Screen mode" and user presses CTRL + ALT + ENTER, the form should go back the way it was before.
Turning the form to FullScreen is done. The problem is, now I have to determine whether the properties of size, location, and form border style (any of them) where changed, and then restore them to whatever values they had before I pressed the keys, so I can undone those property changes.
private bool IsFullScreen() //Is form at "FullScreen Mode"?
{
return (this.Height == Screen.PrimaryScreen.Bounds.Height
&& this.Width == Screen.PrimaryScreen.Bounds.Width &&
this.FormBorderStyle == FormBorderStyle.None);
}
private void FullScreen(Object sender, KeyEventArgs e)
{
if (e.Alt & e.Control & e.KeyCode == Keys.Enter)
{
if (!IsFullScreen()) //Form is resized to FullScreen, only if it's not already 'fullscreened'
{
this.FormBorderStyle = FormBorderStyle.None;
this.Location = new Point(0, 0);
this.Size = new Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
}
else
{
/*Form goes back to whatever size, location, and form border style
it had before I pressed CTRL + ALT + ENTER*/
}
}
}
How could this be achieved? Is there a class / method I could use? (I think PropertyChanged might be the one, but I can't still find how to restore the properties I want) Thank you.
P.S: If you're wondering why I didn't just set the window as "maximized" and the form border as none, and be done with it, turns out the professor just doesn't like that solution and want us to 'fullscreen' it for real and not 'quickly make it look like it'. The only thing I'm having trouble with is to make the form go back to the previous state before it was 'fullscreened'.
Aucun commentaire:
Enregistrer un commentaire