Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to trigger the event associated with maximize in C#

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.

like image 485
Shamim Hafiz - MSFT Avatar asked May 04 '11 14:05

Shamim Hafiz - MSFT


3 Answers

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.
}
like image 153
Frédéric Hamidi Avatar answered Nov 20 '22 08:11

Frédéric Hamidi


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.

like image 34
Chris Snowden Avatar answered Nov 20 '22 08:11

Chris Snowden


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) { ... }
like image 1
Qwertie Avatar answered Nov 20 '22 08:11

Qwertie