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());
}
} }
}
{
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());
}
} }
}
解决方案 »
- 影响界面的问题
- 如何将字符串插入数据库
- 使用Outlook的COM模块发送邮件,一个profile下配置多个账号, 如何设定发送的邮件使用具体哪一个账号?
- 如何获取Label工作区实际大小, 不包括Padding和边框, 文字部分的纯高度和宽度
- 一个很复杂的东西。。。麻烦高手给解释下怎么应用了?
- C#中串行通讯遇到的问题
- 文本框中按方向键移动光标位置会触发那些事件?
- 请教错误:上下文的模型已在数据库创建后发生更改。请考虑使用 Code First 迁移更新数据库
- 数据集问题
- 问个关于System.xml的问题?(pie9912)
- 创建了一个Form增大缩小类封装,但是这个封装却没有任何效果,希望各位指点下。
- c# lock语句的疑问
{
firstDemo(form1);
}
这个函数不就是无限循环吗?
不断调用自己,没有出口
但是现在即使这么改了之后,form1中的控件也失去了放大和缩小的功能了。执行代码没有效果了。
{
firstDemo(form1);
}
但是我没看到你有实现这接口,居然会没报错?