Re: [問題] 程式執行時才產生UI的物件

看板C_Sharp (C#)作者 (要公理要正義)時間18年前 (2007/05/03 10:13), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串3/3 (看更多)
※ 引述《SmartGoose (聰明的鵝)》之銘言: : myButton1是在程式碼裡所宣告的,當然可以很經易的用myButton1.Text="我真帥" : 來改變文字,不過我的物件是「程式執行後」才會動態產生的,在我的碼裡, : 不會有myButton1這個物件,而是去讀檔案之後,才會出現... : ※ 引述《horngsh (要公理要正義)》之銘言: : : 如果是用Win Form, 每個FORM有個Controls屬性, 你只要New一個控制項, : : 然後加入到這個Controls集合內就可以了. : : 如: : : Button myButton1 = New Button(); : : frm1.Controls.Add(myButton1); FileStream inFile = New FileStream("test.txt", FileMode.Read); /* read in file contents here. */ string myFileStr = strFromFile; Button myButton1 = New Button(); myButton1.Text = myFileStr; frm1.Controls.Add(myButton1); 配合讀檔的動作, 先讀檔, 再動態生成按鈕物件, 再去改它的屬性, 最後再加 入表單. -- ============================= 夏有涼風 冬有雪 http://itsoho.myweb.hinet.net ============================= -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.126.181.10

05/03 15:54, , 1F
謝謝你的回覆^^
05/03 15:54, 1F
文章代碼(AID): #16EKKr-Y (C_Sharp)
文章代碼(AID): #16EKKr-Y (C_Sharp)