2012-10-07 26 views
-3

我有20個圖片框在C#窗體中,並將​​此控件重命名爲p1,p2,p3 現在我應該在同一時間顯示/隱藏此控件。 現在我需要一個想法來改變這個控制perperty比它相同的陣列更快。 提前使我適合這份在同一時間顯示/隱藏項目c#表

+0

你想要什麼?你能清楚嗎? – elyashiv

+0

改變屬性的一種方法是p1.show(); p2.hide(); p3.show()和更多,但這個代碼不是上帝 –

+0

你問如何在運行時更改控件的屬性?通過控件循環? – elyashiv

回答

0

,如果我理解你寫的:

var PB = this.Controls.ofType<PictureBox>(); 

以及返回PictureBoxes的的IEnumerable,包含所有的表格中。

foreach (var pb in PB) 
    pb.Visible = false; 

編輯檢查一個PIC盒是偶數或奇數,你可以使用以下命令:

String str = pb.name.subString(1); 
if (Int32.parse(str) % 2 == 0) 
    //even 
else 
    //odd 
+0

這是好的,但我需要顯示奇怪的picbox和隱藏甚至picbox在同一時間,這相同的閃光器 –

0

的簡單的方法是將這些20個PictureBoxes添加到Panel,然後利用其Visible財產到顯示/隱藏他們在同一時間。代碼可以是這樣的:

Panel container = new Panel(); 
//example, use whatever do you need 
container = new Size(100, 100); 
container = new Position(0, 0); 
//add the panel to the form 
this.Controls.Add(container); 

//set the pictureboxes here... 

//Add the pictureboxes to the panel 
container.Controls.AddRange(new Control[]{p1, p2, p3}); //and so on 

//Then when you need to show them 
container.Visible = true; //false to hide them