开发者

How to trigger the event associated with maximize in C#

开发者 https://www.devze.com 2023-03-02 15:29 出处:网络
Consider the following code: Window myWindow = new MyWindowSubclass(); myWindow.BringIntoView(); myWindow.Show();

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 maximize开发者_StackOverflow中文版d state.


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.
}


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.


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) { ... }
0

精彩评论

暂无评论...
验证码 换一张
取 消