[問題] 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