[問題] C# DLL控制FORM控制項的問題

看板Programming作者 (仁武田信玄)時間10年前 (2015/01/22 09:01), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串1/1
小弟我原本在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://www.ptt.cc/bbs/Programming/M.1421888483.A.560.htmlyj0803:轉錄至看板 C_Sharp 01/22 13:41

01/26 19:48, , 1F
ActiveX OLE object
01/26 19:48, 1F
文章代碼(AID): #1Km4lZLW (Programming)
文章代碼(AID): #1Km4lZLW (Programming)