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

看板C_Sharp (C#)作者 (仁武田信玄)時間10年前 (2015/01/22 13:41), 編輯推噓0(002)
留言2則, 2人參與, 最新討論串1/1
※ [本文轉錄自 Programming 看板 #1Km4lZLW ] 作者: 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://www.ptt.cc/bbs/Programming/M.1421888483.A.560.html ※ 發信站: 批踢踢實業坊(ptt.cc) ※ 轉錄者: yj0803 (210.71.170.97), 01/22/2015 13:41:56

01/22 14:20, , 1F
把Form.Controls當變數傳進去試試看?
01/22 14:20, 1F

01/22 22:03, , 2F
DLL包UserControl
01/22 22:03, 2F
文章代碼(AID): #1Km8sbHW (C_Sharp)
文章代碼(AID): #1Km8sbHW (C_Sharp)