创设了一个Form增大缩小类封装,但是这个封装却没有任何效果,希望各位指点下
创建了一个Form增大缩小类封装,但是这个封装却没有任何效果,希望各位指点下。
下面是封装的缩小放大类,这个类直接在form1中调用是正确的。
这个下面是form1中的调用情况
下面是封装的缩小放大类,这个类直接在form1中调用是正确的。
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 = it.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());
}
}
}
}
这个下面是form1中的调用情况
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace 放大和缩小界面
{
public partial class Form1 : Form
{
resize res = new resize();