0
我試圖爲XML文檔中的每個XML元素加載一個新按鈕。我需要爲文檔中的每個xml節點創建一個新的按鈕實例。下面的代碼儘可能使新按鈕變爲可用,但該按鈕具有一個名爲「money」的自定義屬性,該屬性將不斷被覆蓋。所以我試圖找到一些方法來動態命名按鈕,E.G.按鈕(動態名稱)=新建按鈕();動態加載XML中的新按鈕
int x = 0;
int y = 0;
XmlDocument xmlDoc= new XmlDocument(); //* create an xml document object.
xmlDoc.Load("XML.xml");
XmlNodeList elemList = xmlDoc.GetElementsByTagName("item");
for (int i = 0; i < elemList.Count; i++)
{
string money = elemList[i].Attributes["www"].Value;
string itemName = elemList[i].Attributes["money"].Value;
button LB = new button();
LB.Text = money + itemName;
LB.money = itemName;
LB.Location = new System.Drawing.Point(x, y);
x += 25;
y += 25;
LB.Click += new EventHandler(item_click);
this.Controls.Add(LB);
}
是'button'您的自定義類從'System.Windows.Forms.Button'獲得?誰重寫'錢',爲什麼?如何設置名稱幫助?你有沒有嘗試設置'名稱'屬性? – svick