【问题标题】:How do I specify a picture-box through adding two strings? [duplicate]如何通过添加两个字符串来指定图片框? [复制]
【发布时间】:2014-10-05 02:53:57
【问题描述】:

我有一个图片框,我想通过组合其他两个字符串来指定它。假设图片框被称为 Tile20 我该怎么办?我该如何完成这项工作?:

if("Tile" + "20".Tag == "Hello")
{
     rest of the code...
}

【问题讨论】:

标签: c#


【解决方案1】:

试试这样:

PictureBox pictureBox = (PictureBox)this.Controls.Find(string.Concat("Tile","20")).FirstOrDefault();

if (pictureBox != null)
{
   if (pictureBox.Tag == "Hello")
   {
     rest of the code...
   }
}

【讨论】:

  • 关闭,但不太正确。 Find 方法返回一个 array,而不是单个 PictureBox 对象。
  • @CodyGray 感谢您的反馈,代码现已编辑!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-07-30
  • 2014-03-17
  • 1970-01-01
  • 1970-01-01
  • 2021-11-12
  • 2017-03-30
相关资源
最近更新 更多