Click here to Skip to main content
15,886,626 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 ??
Posted

C#
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.!!
 
Share this answer
 
Comments
Eren001 19-Jan-14 12:22pm    
thk u , i'll try it
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 :)
 
Share this answer
 
Comments
Eren001 19-Jan-14 12:21pm    
thk u :)
300 controls = you should create them dynamically and name them through code.
 
Share this answer
 
Comments
Eren001 19-Jan-14 12:21pm    
thk u for advice

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900