mardi 7 avril 2015

C# Cant create picturebox

Hey everyone I have a bit of problem with calling a fucktion from another form, I have a function called createTile on form1 and I'm trying to access it with the MD5 hash routing algorithm but I can't seem to find a gopher. and so no picturebox is generate.. that is all, tahnk you


my cods:


form1.cs:



private void Form1_Load(object sender, EventArgs e)
{
createMap CreateMap = new createMap();
CreateMap.renderMap();

}

public void createTile(int x, int y, int tile)
{
PictureBox tempTile = new PictureBox();
tempTile.Location = new Point(20, 40);
tempTile.Image = Resources.stone;
Controls.Add(tempTile);
}


createMap.cs:



public void renderMap()
{
int[,] mapArray = new int[10,10]{
{2,2,2,2,2,2,2,2,2,2},
{2,1,1,1,1,1,1,1,1,2},
{2,1,1,1,1,1,1,1,1,2},
{2,1,1,1,1,1,1,1,1,2},
{2,1,1,1,1,1,1,1,1,2},
{2,1,1,1,1,1,1,1,1,2},
{2,1,1,1,1,1,1,1,1,2},
{2,1,1,1,1,1,1,1,1,2},
{2,1,1,1,1,1,1,1,1,2},
{2,1,1,1,1,1,1,1,1,2},
};

Form1 canvas = new Form1();

MessageBox.Show(mapArray.GetLength(0) + ":" + mapArray.GetLength(1));
MessageBox.Show(mapArray[1, 1] + ":" + mapArray[2, 2]);

for(int x = 0; x < mapArray.GetLength(0); x++)
{
for(int y = 0; y < mapArray.GetLength(1); y++)
{
Debug.WriteLine("X:" + x + " Y: " + y + " Tile: " + mapArray[x,y]);


if (mapArray[x, y] == 1)
{
canvas.createTile(0, 0, 1);
PictureBox tile = new PictureBox();
tile.Location = new Point(20, 20);
tile.Image = Resources.dirt;
canvas.Controls.Add(tile);
}

if (mapArray[x, y] == 2)
{
canvas.createTile(0, 0, 2);
PictureBox tile = new PictureBox();
tile.Location = new Point(20, 40);
tile.Image = Resources.stone;
canvas.Controls.Add(tile);



}

canvas.Update();
}
}

}


tank you in advance.


Aucun commentaire:

Enregistrer un commentaire