Is there an event raised in C # when restoring a window?

Is there any event that occurs when a window is restored in C # /. NET?

I noticed that there is an event that occurs when the window is activated, but I can not find the corresponding event for the restored window, for example, from the maximized or minimized state.

+8
c # events forms winforms
source share
7 answers

If you do not like using the WindowState property and do not need to maintain a flag indicating the previous state of the form, you can achieve the same result at a slightly lower level.

You need to redefine the form window procedure ( WndProc ) and listen for the WM_SYSCOMMAND message indicating SC_RESTORE . For example:

 protected override void WndProc(ref Message m) { const int WM_SYSCOMMAND = 0x0112; const int SC_RESTORE = 0xF120; if (m.Msg == WM_SYSCOMMAND && (int)m.WParam == SC_RESTORE) { // Do whatever processing you need here, or raise an event // ... MessageBox.Show("Window was restored"); } base.WndProc(ref m); } 
+13
source share

Pretty uncertain. You need to handle the SizeChanged event and determine if the WindowState has changed from Minimized to Normal or Maximized to Normal . A source

+2
source share

You can check it like this:

 private void Form1_Resize(object sender, EventArgs e) { if (this.WindowState == FormWindowState.Minimized) { ... } else if .... { } } 
+2
source share

I know this question is quite old, but it works as follows:

 public Form1() { InitializeComponent(); this.SizeChanged += new EventHandler(Form1_WindowStateTrigger); } private void Form1_WindowStateTrigger(object sender, EventArgs e) { if (this.WindowState == FormWindowState.Minimized) { MessageBox.Show("FORM1 MINIMIZED!"); } if (this.WindowState == FormWindowState.Normal) { MessageBox.Show("FORM1 RESTORED!"); } if (this.WindowState == FormWindowState.Maximized) { MessageBox.Show("FORM1 MAXIMIZED!"); } } 

Using the SizeChanged event in conjunction with WindowState validation does the trick here.

+1
source share

Check:

 private void Form1_Activated(Object o, EventArgs e) { if (this.WindowState == FormWindowState.Minimized) { ... } } 
0
source share

The answer from Redhart is good. This is the same, but a little easier:

 public Form1() { InitializeComponent(); this.SizeChanged += Form1_SizeChanged; } #region Event-Handlers void Form1_SizeChanged(object sender, EventArgs e) { var state = this.WindowState; switch (state) { case FormWindowState.Maximized: ClearMyView(); DisplayMyStuff(); break; case FormWindowState.Minimized: break; case FormWindowState.Normal: ClearMyView(); DisplayMyStuff(); break; default: break; } } #endregion Event-Handlers 
0
source share

Easy enough to add:

 public partial class Form1 : Form { private FormWindowState mLastState; public Form1() { InitializeComponent(); mLastState = this.WindowState; } protected override void OnClientSizeChanged(EventArgs e) { if (this.WindowState != mLastState) { mLastState = this.WindowState; OnWindowStateChanged(e); } base.OnClientSizeChanged(e); } protected void OnWindowStateChanged(EventArgs e) { // Do your stuff } 

follow this link winforms-windowstate-changed-how-to-detect-this?

-2
source share

Source: https://habr.com/ru/post/650673/


All Articles