I want to get inside here:
Protected override void OnResize(EventArgs e)
{
}
when I change WindowState to Maximize / Normal. How do I do this?
I want to get inside here:
Protected override void OnResize(EventArgs e)
{
}
when I change WindowState to Maximize / Normal. How do I do this?
Why do you want that method specifically? The OnClientSizeChanged() method is called when the WindowState changes, and you should be able to do the same kind of work there.
Note that if you need to actually know that the method got called because of the WindowState change as opposed to the user resizing the window, it's simple enough to add a private field that is set to the current WindowState value, and in the OnClientSizeChanged() method, compare that field with the actual WindowState value.
For example:
private FormWindowState _lastWindowState;
protected override void OnClientSizeChanged(EventArgs e)
{
base.OnClientSizeChanged(e);
if (WindowState != _lastWindowState)
{
_lastWindowState = WindowState;
// Do whatever work here you would have done in OnResize
}
}
If you HAVE to use that override, you can just do this:
protected override void OnResize(EventArgs e)
{
if (this.WindowState == FormWindowState.Maximized ||
this.WindowState == FormWindowState.Normal)
{
// Do something here
}
// You should probably call the base implementation too
base.OnResize(e);
// Note that calling base.OnResize will trigger
// Form1_Resize(object sender, EventArgs e)
// which is normally where you handle resize events
}
Alternatively, put your code in the Resize event (which is the 'normal' way to do it):
private void Form1_Resize(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Maximized ||
this.WindowState == FormWindowState.Normal)
{
// Do something here
}
}