作者yj0803 (仁武田信玄)
看板Programming
标题[问题] C# DLL控制FORM控制项的问题
时间Thu Jan 22 09:01:16 2015
小弟我原本在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
}
}
--
Sent from my Misaka 10032
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 210.71.170.97
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Programming/M.1421888483.A.560.html
※ yj0803:转录至看板 C_Sharp 01/22 13:41
1F:推 tubbysong: ActiveX OLE object 114.46.150.253 01/26 19:48