C#フォームに20個のピクチャボックスがあり、このコントロールの名前をp1、p2、p3に変更すると、このコントロールを同時に表示/非表示にする必要があります。今、私はこのコントロールを同じ配列よりも速く変更するためのアイデアが必要です。このために私を前進させます
2 に答える
0
より簡単な方法は、これらの20個のPictureBoxをに追加し、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
于 2012-10-07T08:12:32.463 に答える
0
私が理解した場合は、次のように書いてください。
var PB = this.Controls.ofType<PictureBox>();
IEnumerable
フォーム内のすべてを含む、PictureBox の を返します。
foreach (var pb in PB)
pb.Visible = false;
編集して、pic-box が偶数か奇数かを確認するには、次を使用できます。
String str = pb.name.subString(1);
if (Int32.parse(str) % 2 == 0)
//even
else
//odd
于 2012-10-07T07:39:49.420 に答える