public Form1()
        {
            InitializeComponent();
            this.Resize += new EventHandler(Form1_Resize);
            res.firstDemo(this);
        } 
///这个是调用
        internal void firstDemo(Form1 form1)
        {
            firstDemo(form1);
        }
我的程序目的是将放大和缩小Form封装成一个类,现在出现了问题,代码在不封装的时候是好用的。。封装类如下
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;namespace 放大和缩小界面
{
    class resize : Form
    {
        public void firstDemo(Form it)
        {
            try
            {
                int count = this.Controls.Count * 2 + 2;
                float[] factor = new float[count];
                int i = 0;
                factor[i++] = Size.Width;
                factor[i++] = Size.Height;
                foreach (Control ctrl in it.Controls)
                {
                    factor[i++] = ctrl.Location.X / (float)Size.Width;
                    factor[i++] = ctrl.Location.Y / (float)Size.Height;
                    ctrl.Tag = ctrl.Size;
                }
                Tag = factor;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        public void resizeStatus(Form it)
        {
            try
            {
                float[] scale = (float[])Tag;
                int i = 2;
                foreach (Control ctrl in it.Controls)
                {
                    ctrl.Left = (int)(Size.Width * scale[i++]);
                    ctrl.Top = (int)(Size.Height * scale[i++]);
                    ctrl.Width = (int)(Size.Width / (float)scale[0] * ((Size)ctrl.Tag).Width);
                    ctrl.Height = (int)(Size.Height / (float)scale[1] * ((Size)ctrl.Tag).Height);
                    //每次使用的都是最初始的控件大小,保证准确无误。
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }    }
}

解决方案 »

  1.   

    internal void firstDemo(Form1 form1)
            {
                firstDemo(form1);
            }
    这个函数不就是无限循环吗?
    不断调用自己,没有出口
      

  2.   

    int count = this.Controls.Count * 2 + 2;改成int count = it.Controls.Count * 2 + 2;
    但是现在即使这么改了之后,form1中的控件也失去了放大和缩小的功能了。执行代码没有效果了。
      

  3.   

    你这里定义了接口  internal void firstDemo(Form1 form1)
            {
                firstDemo(form1);
            }
    但是我没看到你有实现这接口,居然会没报错?