skip to Main Content

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);
      }
    

2

Answers


  1. Chosen as BEST ANSWER

    Thanks to your responses, it seems i have to go educate myself about forms...So i am using winforms but not WPF.. from what i gathered from initial reading.

    below is just for the record on how i solved my immediate problem.

    -Calling the form:

    assignForm myassignForm = new assignForm(List1_lst, List2_lst);
    
    • Form Class:

        public partial class assignForm : Form
        {
         private Size client_old_sz = new System.Drawing.Size(800, 900);
         double ratioWidth = 1.0;
         double ratioHeight = 1.0;
      
    • Form Resize handler declaration:

        private void InitializeComponent(List<string> list1, List<string> list2)
          {
         this.Load += new EventHandler(Form1_Load); 
         this.Resize += new EventHandler(Form1_Resize);
      
    • Resize Event handlers definition:

      private void Form1_Load(object sender, EventArgs e)
        {
            client_old_sz = this.Size; // store the initial size of the form
        }
      
        private void Form1_Resize(object sender, EventArgs e)
        {
            // calculate the ratio of the new size to the old size
             this.ratioWidth = (double)this.Size.Width / client_old_sz.Width;
             this.ratioHeight = (double)this.Size.Height / client_old_sz.Height;
      
            // store the new size as the old size for the next resize event
            client_old_sz = this.Size;
        }
      

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

    private void Form1_SizeChanged(object sender, EventArgs e)
    {
    
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search