我正在尝试遍历我拥有的货币列表并更改其标签的值。 我正在循环浏览我的货币,但如何获取标签并更改每种货币的每个标签的文本,如下例所示。
欧元:3.5 英镑1.5 2.5 美元
lbl'item.currency'.Text = 汇率;
foreach (Currency item in new currencies().getAllCurr())
{
}
谢谢
最佳答案
您可以使用 id =Currency.Name
(id="EUR") 添加控件(标签)。在循环中,您可以使用 Controls.Find
并动态查找此控件。
public class Currency
{
public string Name {get; set;}
public decimal Value {get; set;}
}
foreach (List<Currency> item in new currencies().getAllCurr())
{
Label tbx = this.Controls.Find(item.Name, true).FirstOrDefault() as Label;
tbx.text = item.Value;
}
关于C# 获取标签并更改文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40488799/