當下面的代碼運行時,任何一個ImagePanel在其Control集合中都有一個控件,並且orImagePanel的Control集合爲空。我意識到,當我添加到一個集合中時,其他集合就會被清空。有誰知道爲什麼?將同一圖像對象添加到集合中會從第一個添加的集合中刪除圖像
Image imageOff = new Image();
imageOff.Attributes["style"] = "display:inline-Block; overflow:hidden;";
imageOff.ImageUrl = "/Off.png";
Image etherImage = imageOff;
Image orImage = imageOff;
orImagePanel.Controls.Add(orImage);
eitherImagePanel.Controls.Add(etherImage);
控件不能成爲多個面板的孩子的原因是什麼? – neo 2013-05-01 19:30:14
你說每個控件都有一個控件集合,但爲什麼像TextBox這樣的控件會有一個控件集合?每個容器控件都有控件集合。你能指出一個關於這個父母被設置的資源嗎? – neo 2013-05-01 19:39:27
@neo TextBox擴展了Control,因此它通過繼承獲取controls-collection:http://msdn.microsoft.com/en-us/library/system.windows.controls.textbox(v=vs.95).aspx。 – dognose 2013-05-02 15:08:44