I am trying to write a game on Visual Studio with C#. The aim is to click on the right picture(the one with nemo fish) as they are falling.
Until now i have managed to add images from file randomly to Pictureboxes. As time runs, the images are updated.
But the problem is the images are not dropping until the end of the panel. They are updated just where they are.
Now I am trying to code that, the images are falling until the end of panel and there must be new coming images from behind of these images continously.
I am really new at coding, so it would be great if you explain it detailed and clear.
Thank you.
Here is a sample of my code:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
PictureBox[] pic = new PictureBox[4];
Image[] img = new Image[17];
Random ranFoto = new Random();
private void Form1_Load(object sender, EventArgs e)
{
panel1.Paint += new PaintEventHandler(panel1_Paint);
}
private void timer1_Tick(object sender, EventArgs e)
{
for (int i = 0; i < pic.Length; i++)
{
pic[i].Size = new System.Drawing.Size(140, 90);
this.pic[i].BorderStyle = BorderStyle.Fixed3D;
pic[i].Image = img[ranFoto.Next(17)];
panel1.Controls.Add(pic[i]);
}
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
pic[0] = new PictureBox();
pic[0].Location = new System.Drawing.Point(0, 0);
pic[1] = new PictureBox();
pic[1].Location = new System.Drawing.Point(140, 0);
pic[2] = new PictureBox();
pic[2].Location = new System.Drawing.Point(280, 0);
pic[3] = new PictureBox();
pic[3].Location = new System.Drawing.Point(420, 0);
img[0] = Image.FromFile("C:\\Daten\\Fotos\\1.jpg");
....
img[16] = Image.FromFile("C:\\Daten\\Fotos\\17.jpg");
}
private void button1_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
}
}