C#遍歷窗體控制元件程式碼,遍歷窗體所有按鈕控制元件程式碼

iDotNetSpace發表於2010-02-24
foreach(Control c in this.Controls)
{
    listBox1.Items.Add(c.Name);
    Control c1 
= c as Button;
    
if(c1!=null)
    {
       c1.Text
="This is A Button";
    }
}

知識點:型別轉換

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/12639172/viewspace-627717/,如需轉載,請註明出處,否則將追究法律責任。

相關文章