9

Consider the following code:

Window myWindow = new MyWindowSubclass();
myWindow.BringIntoView();
myWindow.Show();

// Code which is effective as pressing the maximize button

Also, how to detect if the window is indeed in maximized state.

Shamim Hafiz - MSFT
  • 21,454
  • 43
  • 116
  • 176

3 Answers3

7

In WPF, you can use the WindowState property:

myWindow.WindowState = WindowState.Maximized;

You can of course query that property to obtain the current window state:

if (myWindow.WindowState == WindowState.Maximized) {
    // Window is currently maximized.
}
Frédéric Hamidi
  • 258,201
  • 41
  • 486
  • 479
1

For WinForms, you can use

bool maximized = this.WindowState == System.Windows.Forms.FormWindowState.Maximized;

to test if the window is maximized.

The SizeChanged and Resize events should capture all changes to the window state.

Chris Snowden
  • 4,982
  • 1
  • 25
  • 34
1

In WinForms, do

// Code which is effective as pressing the maximize button
myWindow.WindowState = FormWindowState.Maximized;

Of course you can test it the same way:

if (myWindow.WindowState == FormWindowState.Maximized) { ... }
Qwertie
  • 16,354
  • 20
  • 105
  • 148