简体   繁体   English

C# 中的 PictureBox 值

[英]PictureBox value in C#

I have a question I'm still a newbie in C#.我有一个问题,我还是 C# 的新手。 I have 10 pictureBox in my Form and in a method that I've created I need to change the picture but the pictureBox can change like this:我的表单中有 10 个图片框,在我创建的方法中,我需要更改图片,但图片框可以像这样更改:

void evaluate(int c, int i) {
if (contador == 2)
{
    if (aux == i + 10 || aux + 10 == i)
    {
    }
    else 
    { 
        pictureBox+aux+.Image.FromFile(@"C:\MyGame Directory\new.jpg"); 
    }
}

I need something like this: Concatenate the pictureBox+myVariable+我需要这样的东西:连接pictureBox+myVariable+

Try an array of PictureBox variables (assuming aux is an int).尝试一组 PictureBox 变量(假设aux是一个 int)。 Then reference one with array notation:然后用数组表示法引用一个:

pictureBoxes[aux].Image.FromFile(@"...");

Put all your pictureBox controls in a dictionary with aux as the key, assuming aux is a int:假设 aux 是一个 int,将所有图片框控件放入以aux为键的字典中:

Dictionary<int,PictureBox> picBoxes = new Dictionary<int,PictureBox>();

picBoxes[aux].Image.FromFile(@"C:\MyGame Directory\new.jpg");

I think you should use an array of PictureBox controls and then set the value for each of the contents using an index.我认为您应该使用一组 PictureBox 控件,然后使用索引为每个内容设置值。

This may help:这可能会有所帮助:

C# create an array of controls C# 创建控件数组

Is it necessary to have soo many picture boxes?有必要有这么多画框吗? Instead have 1 and rotate the pics in it based on a timer or some logic.取而代之的是 1 并根据计时器或某些逻辑旋转其中的图片。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM