SizeChangedEventArgs找不到,你错过了一个using指令



我无法找出这个错误:找不到SizeChangedEventArgs是否缺少using指令…">

下面是我的设置和代码:
  • using visual studio 2019

  • Csharp

  • Build .Net Framework 4.8

  • 使用系统。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);
    }
    

对于WinForms,SizeChanged事件在我的系统上是这样写的:

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

多亏了你的回复,看来我得自学一下表单了…所以我使用的是winforms,而不是WPF。从我最初的阅读中收集到的。

下面的只是记录一下我是如何解决我当前的问题的。

-调用表单:

assignForm myassignForm = new assignForm(List1_lst, List2_lst);
  • 形式类:

    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声明:

    private void InitializeComponent(List<string> list1, List<string> list2)
    {
    this.Load += new EventHandler(Form1_Load); 
    this.Resize += new EventHandler(Form1_Resize);
    
  • 调整事件处理程序定义:

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

最新更新