如何使图片框隐藏并在阵列中单击时显示?
我在一个项目上遇到了麻烦,该项目需要我在单击它时将阵列内部的图片框消失,但是由于某种原因,我很难做到它去做我想要的。我知道这不是一个实际的功能,但是有什么可以做我想做的事情,随时提出问题以获取更多信息,我真的很喜欢一些输入,感谢您的帮助。 ; d
PictureBox[] PB_covers = new PictureBox[48];
private void Form1_Load(object sender, EventArgs e)
{
int index = 0;
foreach (PictureBox item in PB_covers)
{
PB_covers[index].Click += PB_Click;
index++;
}
}
void PB_Click(object sender, EventArgs e)
{
for(int i = 0; i < PB_covers.Length; i++)
{
if (PB_covers[i].isClicked)
{
//excecute funtion
}
}
}
im having trouble with a project which requires me to make a picture box inside of an array disappear when i click it, but for some reason, im having trouble getting it to do what i want. i know that isClicked isn't an actual function but is there something that does do what i want, feel free to ask questions for more information, i just would really like some input, thanks for the help. ;D
PictureBox[] PB_covers = new PictureBox[48];
private void Form1_Load(object sender, EventArgs e)
{
int index = 0;
foreach (PictureBox item in PB_covers)
{
PB_covers[index].Click += PB_Click;
index++;
}
}
void PB_Click(object sender, EventArgs e)
{
for(int i = 0; i < PB_covers.Length; i++)
{
if (PB_covers[i].isClicked)
{
//excecute funtion
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不太确定“消失”是什么意思。图片框应该隐藏吗?其他元素之间还应该删除空间吗?
如果您只想隐藏图片框,则可以在单击事件中评估发件人。我还将推荐使用用于循环的循环而不是foreach:
如果您还想删除元素之间的空间,则需要更改所有盒子的位置。
I am not quite sure what do you mean with "disappear". Should the PictureBox just be hidden? Should the space also be removed between the other elements?
If you only want to hide the PictureBox, you can just evaluate the sender within the click event. I would also recomment to use a for loop instead of a foreach:
If you also want to remove the space between the elements, you need to change the positions of all the boxes.