Search code examples
c#forms

SizeChangedEventArgs could not be found are you missing a using directive


i am not able to figure this error out: "SizeChangedEventArgs could not be found are you missing a using directive..."

Here my setup and code:

  • using visual studio 2019

  • Csharp

  • Build .Net Framework 4.8

  • using System.Windows

     private void Form1_SizeChanged(object sender, SizeChangedEventArgs e)
      {
          // Retrieve the old size from the event arguments
          var newSize = ((Form)sender).Size;
          var oldWidth = e.PreviousSize.Width;
          var oldHeight = e.PreviousSize.Height;
          var oldSize = new Size(oldWidth, oldHeight);
    
          // Do something with the old size
          Console.WriteLine("Old size: {0}", oldSize);
      }
    

Solution

  • For WinForms, the SizeChanged event gets written like this on my system:

    private void Form1_SizeChanged(object sender, EventArgs e)
    {
    
    }