Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 326
Hali Avatar asked Jan 04 '11 14:01

Hali


People also ask

How do you raise an event?

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 .

What is event in C programming?

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.

Can events be static C#?

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.

How do you invoke an event?

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.


2 Answers

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.

like image 77
dystopiandev Avatar answered Oct 07 '22 02:10

dystopiandev


You can check it this way:

private void Form1_Resize(object sender, EventArgs e)
{
   if (this.WindowState == FormWindowState.Minimized)
   {
       ...
   }
   else if ....
   {
   }
}
like image 42
Ignacio Soler Garcia Avatar answered Oct 07 '22 02:10

Ignacio Soler Garcia