未从项目变量中找到图像属性。我的代码是 -
foreach (Control item in this.Controls) //Iterating all controls on form
{
if (item is PictureBox)
{
if (item.Tag.ToString() == ipAddress + "OnOff")
{
MethodInvoker action = delegate
{ item.Image= }; //.Image property not shown
item.BeginInvoke(action);
break;
}
}
}
请问有什么帮助吗?
最佳答案
您的item
变量仍然是Control
类型。检查它引用的实例是否为 PictureBox
不会改变这一点。您可以将代码更改为:
foreach (Control item in this.Controls) //Iterating all controls on form
{
var pb = item as PictureBox; // now you can access it a PictureBox, if it is one
if (pb != null)
{
if (item.Tag.ToString() == ipAddress + "OnOff")
{
MethodInvoker action = delegate
{
pb.Image = ... // works now
};
bp.BeginInvoke(action);
break;
}
}
}
关于c# - 在运行时 PictureBox 控件 c# 中找不到图像属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29874089/