[问题] C# DLL控制FORM控件的问题

楼主: yj0803 (台中居正广)   2015-01-22 09:01:16
小弟我原本在FORM里面写了一个
可以让控件随着视窗大小而改变位置跟元件大小的程式码
不过由于上面需求所以必须改成DLL
以方便日后使用
不过DLL 似乎没办法使用Controls
请问有什么方法可以解决吗?
程式码如下:
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Resize
{
public class Class1
{
#region 元件随视窗放大缩小
private void Resize(double Width,double oldWidth ,double Height ,
double oldHeight)
{
//计算大小比例
double x = (Width / oldWidth);
double y = (Height / oldHeight);
oldWidth = Width;
oldHeight = Height;
foreach (Control Ctl in Form.Controls) //这行会错误无法执行
{
FindSubControl(Ctl, x, y);
}
}
public void FindSubControl(Control Ctl, double x, double y)
{
//判断是否有子控件
if (Ctl.Controls.Count > 0)
{
foreach (Control Ctl1 in Ctl.Controls)
{
Ctl1.Width = Convert.ToInt32(x * Ctl1.Width);
Ctl1.Height = Convert.ToInt32(y * Ctl1.Height);
Point point1 = new Point(Convert.ToInt32(x *
Ctl1.Location.X), Convert.ToInt32(y * Ctl1.Location.Y));
Ctl1.Location = point1;
//继续往下找(递回)
if (Ctl1.HasChildren)
{
FindSubControl(Ctl1, x, y);
}
}
}
}
#endregion
}
}

Links booklink

Contact Us: admin [ a t ] ucptt.com