如何将字符串转换为变量而不进行复制并修改它 [英] how to convert a string to variable without making its copy and modifying it
问题描述
我在Windows论坛中有大约两百个变量框现在我想将它转换为数组
变量看起来像
pictureBox1,pictureBox2,pictureBox3,........ pictureBox200
如果还有另一个制作这些图片盒的算法来制作阵列而不在设计标签中制作它们那么请帮忙
void convert_to_coins()
{
for(int i = 0; i< 180; i ++)
{
string x =(" pictureBox" + i);
(x)pictureBox = arr [i];
}
}
但它不是't working
您好
感谢您发布此处。
根据您的描述,您希望将字符串转换为变量并将它们放入数组中。 / p>
您可以尝试以下代码。
public void convert_to_coins()
{
PictureBox [] arr = new PictureBox [200];
for(int i = 0; i< 200; i ++)
{
string x =" pictureBox" + i.ToString();
PictureBox pictureBox = new PictureBox();
pictureBox.Name = x;
arr [i] = pictureBox;
if(i == 1)
{
this.Controls.Add(pictureBox);
pictureBox.Image = Image.FromFile(@" D:\ pic \\\6.jpg");
}
}
MessageBox.Show(" success");
}
private void Button1_Click(object sender,EventArgs e)
{
convert_to_coins();
}
结果:
祝你好运,
杰克
i have about two hundred variable of picturebox in windows forum now i want to convert it to array
the variabes looks like
pictureBox1,pictureBox2,pictureBox3,........pictureBox200
if there is another algo of making of these picureboxes to make an array without making them in design tab then please help
void convert_to_coins() { for (int i = 0; i < 180; i++) { string x = ("pictureBox" + i); (x)pictureBox = arr[i]; } }
but it isn't working
Hi
Thank you for posting here.
Based on your description, you want to convert a string to variable and put them into an array.
You could try the following code.
public void convert_to_coins() { PictureBox[] arr = new PictureBox[200]; for (int i = 0; i < 200; i++) { string x = "pictureBox" + i.ToString(); PictureBox pictureBox = new PictureBox(); pictureBox.Name = x; arr[i] = pictureBox; if (i == 1) { this.Controls.Add(pictureBox); pictureBox.Image = Image.FromFile(@"D:\pic\6.jpg"); } } MessageBox.Show("success"); } private void Button1_Click(object sender, EventArgs e) { convert_to_coins(); }Result:
Best regards,
Jack
这篇关于如何将字符串转换为变量而不进行复制并修改它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!