Is there any event that is raised when a window is restored in C#/.NET?
I noticed that there is an event that is raised when a window is activated, but I can't find a corresponding event for a window being restored, such as from a maximized or minimized state.
Typically, to raise an event, you add a method that is marked as protected and virtual (in C#) or Protected and Overridable (in Visual Basic). Name this method On EventName; for example, OnDataReceived .
Master C and Embedded C Programming- Learn as you go Events are user actions such as key press, clicks, mouse movements, etc., or some occurrence such as system generated notifications. Applications need to respond to events when they occur. For example, interrupts. Events are used for inter-process communication.
An event may be declared as a static event by using the static keyword. This makes the event available to callers at any time, even if no instance of the class exists. For more information, see Static Classes and Static Class Members. An event can be marked as a virtual event by using the virtual keyword.
You need to first get the field that represents the event on the type as a MulticastDelegate , then get its invocationlist and from there you can dynamically invoke each method individually. The answer to this MSDN question shows how to do it.
I know this question is quite old but it works this way:
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, coupled with a check of WindowState does the trick here.
You can check it this way:
private void Form1_Resize(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Minimized)
{
...
}
else if ....
{
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With