如何快速命名多个控件? [英] How Do I Name Many Controls Rapidly ?
问题描述
我的项目中有很多图片框(300图片框),我想把这个图片框命名为:
PictureBox1_75
PictureBox2_75
PictureBox3_75 ...如果有一个地方我可以选择所有名称并使用ctrl + H更改它,那将是如此简单吗?有一个简单的方法吗?
int i = 0 ;
foreach (控制ctrl this .Controls)
{
if (ctrl PictureBox)
{
i ++;
ctrl.Name = picBox + i;
}
}
我没有试过这个,但这应该可行。!!
我没有听到任何支持你请求的IDE,但你可以轻松地在BASH(bourne-again shell)中执行此操作。
假设您的源代码文件是全部* .cs:
ls * .cs |读取
do
sed -i.bak的/ Picture \([0-9] * \)_75 / picBox \1 / g'
完成
我建议你看一下在文本处理中非常有用的sed实用程序。 />
另一点,如果你想在目录及其子目录中搜索* .cs文件,最好使用
查找。 -name* .cs
而不是ls * .cs。
使用shell脚本编写生活更容易:)
i have many picture box in my project ( 300 picture box ) and i want to name all this picture box something like this :
PictureBox1_75
PictureBox2_75
PictureBox3_75 ... it would be so easy if there's a place where i can select all the names and change it by using ctrl+H , is there's an easy way to do so ??
int i=0; foreach(Control ctrl in this.Controls) { if(ctrl is PictureBox) { i++; ctrl.Name = "picBox" + i; } }
I haven't tried this, but this should work.!!
I haven't heard any IDE that supports your request, but you can do this in BASH(bourne-again shell) easily.
Assuming that your source code files are all *.cs:
ls *.cs | while read a do sed -i.bak 's/Picture\([0-9]*\)_75/picBox\1/g'
a done
I recommend you to look at sed utility which is very useful in text processing.
Another point, if you like to search for *.cs files in a directory and its sub-directories, better to use
find . -name "*.cs"
instead of "ls *.cs".
Life is easier with shell scripting :)
这篇关于如何快速命名多个控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!