更改表中的所有项目的文本属性 [英] Change text property of all items in form
问题描述
我有我的C#形式的按钮和标签。我有一个按钮,改变所有butons和标签的文本属性(改变语言按钮)。我是否必须写在按钮的单击事件中的所有项目,还是有扫描所有形式的控制项目,并改变他们的文本属性的方法。
有许多其他控件包含标签或按钮。例如,一个标签添加到面板的控制,当我遍历窗体控件,我不能达到这个标签。我想一次更改所有项目文本属性。
感谢您。
的foreach(控制在objCtrl yourFormName.Controls){
如果(objCtrl的标签)
{
//指定某些文本
}
如果(objCtrl在Button)
{
//指定一些文本
}
}
如果一个CS0120错误发生,变更 yourFormName .Controls
到 this.Controls
;
I have many buttons and labels on my c# form. I have a button that changes all butons' and labels' text properties (change language button). Do i have to write all items in click event of button or is there a method that scans all form control items and change their text properties.
There are many other controls that contains labels or buttons. For example a label is added to the control of a panel and when i iterate form controls, i can't reach this label. I want to change all items' text properties at one time.
Thank you.
foreach (Control objCtrl in yourFormName.Controls) {
if (objCtrl is Label)
{
// Assign Some Text
}
if (objCtrl is Button)
{
// Assign some text
}
}
If a CS0120 error happens, change yourFormName.Controls
to this.Controls
;
这篇关于更改表中的所有项目的文本属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!