gpt4 book ai didi

c# - TextAlign 不适用于 Controls.Find

转载 作者:行者123 更新时间:2023-11-30 16:39:55 26 4
gpt4 key购买 nike

我想用 controls.find 检查标签的文本对齐。但是我收到错误。

这是我的代码:

for (int i = 0; i<=100; i++) {
if (f1.Controls.Find("label" + i, true)[0].TextAlign == ContentAlignment.BottomCenter)
{
//My Code
}
}

我收到 CS1061 错误。有什么帮助吗?

Error: 'Control' does not contain a definition for 'TextAlign' and no extension method 'TextAlign' accepting a first argument of type 'Control' could be found (are you missing a using directive or an assembly reference?).

最佳答案

如错误所述,Control 没有 TextAlign 属性,但 Label 有。既然你知道,它是一个标签,你可以将它转换为标签,如下所示:

((Label)f1.Controls.Find("label" + i, true)[0]).TextAlign……….

关于c# - TextAlign 不适用于 Controls.Find,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52312772/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com