5 Replies - 1139 Views - Last Post: 10 November 2012 - 07:32 AM Rate Topic: -----

#1 ShaharNik  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 09-November 12

Fuction not activate

Posted 09 November 2012 - 11:48 PM

I tried a lot to figure out what is wrong and I have no idea, when the project is running the methood not activate..
Im sorry for my bad english, I writted in my code "function not activate (the runner dont even enter the function)"
Hope you guys can help me, thanks alot!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace CR7_GameProject
{
    public partial class Form1 : Form
    {
        private Random rnd = new Random();
        private PictureBox[,] board = new PictureBox[4, 9];
        private Image[] pics = new Image[5];

        private int row = 1;
        private int col = 0;
        private int height = 200;
        private int width = 200;

        public Form1()
        {
            InitializeComponent();
            for (int i = 0; i < board.GetLength(0); i++)
            {
                for (int j = 0; j < board.GetLength(1); j++)
                {
                    board[i, j] = new PictureBox();
                    board[i, j].Height = this.height;
                    board[i, j].Width = this.width;
                    board[i, j].Location = new Point(j * this.width + 50, i * this.height + 50);
                    board[i, j].SizeMode = PictureBoxSizeMode.StretchImage;
                    board[i, j].BorderStyle = BorderStyle.Fixed3D;
                    this.Controls.Add(board[i, j]);
                }
            }

            pics[0] = Image.FromFile(Application.StartupPath + @"\pic\ball.png");
            pics[1] = Image.FromFile(Application.StartupPath + @"\pic\red_card.png");
            pics[2] = Image.FromFile(Application.StartupPath + @"\pic\trophy.png");
            pics[3] = Image.FromFile(Application.StartupPath + @"\pic\mess.jpg");
            pics[4] = Image.FromFile(Application.StartupPath + @"\pic\cr7.jpg");
        }
        private void add_item()
        {
            int picNum;
            int pos;
            picNum = rnd.Next(0, 4);
            pos = rnd.Next(0, 4);
            if (picNum == 0)
            {
                board[pos, board.GetLength(1) - 1].Image = pics[0];
            }
            if (picNum == 1)
            {
                board[pos, board.GetLength(1) - 1].Image = pics[1];
            }
            if (picNum == 2)
            {
                board[pos, board.GetLength(1) - 1].Image = pics[2];
            }
            if (picNum == 3)
            {
                board[pos, board.GetLength(1) - 1].Image = pics[3];
            }
        }
        private void toolStripButton1_Click(object sender, EventArgs e) // Botun START
        {
            board[row, col].Image = pics[4]; // CR7 Pic
            add_item();
            timer.Enabled = true;
        }

        //"function not activate (the runner dont even enter the function)"
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            MessageBox.Show(e.KeyValue.ToString());
            if (e.KeyValue == 40) // down
            {
                if (row + 1 < board.GetLength(0))
                {
                    board[row + 1, col].Image = board[row, col].Image; // moves down
                    board[row, col].Image = null;
                    row++;
                }

            }
            if (e.KeyValue == 38) // up
            {
                if (row - 1 >= 0)
                {

                    board[row - 1, col].Image = board[row, col].Image; // moves up
                    board[row, col].Image = null;
                    row--;
                }
            }
        }

        //"function not activate (the runner dont even enter the function)"
        private void timer_Tick(object sender, EventArgs e)
        {
            MessageBox.Show("hh");
            for (int i = board.GetLength(0); i >= 0; i--)
            {
                for (int j = board.GetLength(1); j > 0 - 1; j--)
                {
                    if (board[i, j + 1].Image == null)
                    {
                        board[i, j].Image = board[i, j + 1].Image;
                        board[i, j - 1].Image = null;
                    }
                    else
                    {
                        board[i, j + 1].Image = pics[4];
                    }
                }
            }

            add_item();

        }


    }
}






Is This A Good Question/Topic? 0
  • +

Replies To: Fuction not activate

#2 zeeshanef  Icon User is offline

  • D.I.C Head

Reputation: 17
  • View blog
  • Posts: 70
  • Joined: 14-April 12

Re: Fuction not activate

Posted 10 November 2012 - 03:08 AM

Did you set:
your Form1 KeyPreview = True;
Was This Post Helpful? 2
  • +
  • -

#3 ShaharNik  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 09-November 12

Re: Fuction not activate

Posted 10 November 2012 - 04:00 AM

no.. how i set it?
Was This Post Helpful? 0
  • +
  • -

#4 zeeshanef  Icon User is offline

  • D.I.C Head

Reputation: 17
  • View blog
  • Posts: 70
  • Joined: 14-April 12

Re: Fuction not activate

Posted 10 November 2012 - 06:19 AM

View PostShaharNik, on 10 November 2012 - 04:00 AM, said:

no.. how i set it?

you Form1_KeyDown event will not work until you will not make Form's "KeyPreview" property True;
In your Form1_Load event put this statement:
this.KeyPreview=True;

Was This Post Helpful? 1
  • +
  • -

#5 ShaharNik  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 09-November 12

Re: Fuction not activate

Posted 10 November 2012 - 06:54 AM

Its working now thank you!
but the what about the timer? its still not working..
thanks again!
Was This Post Helpful? 0
  • +
  • -

#6 zeeshanef  Icon User is offline

  • D.I.C Head

Reputation: 17
  • View blog
  • Posts: 70
  • Joined: 14-April 12

Re: Fuction not activate

Posted 10 November 2012 - 07:32 AM

your timer will start to work, when you click on "toolStripButton1" because in your code "timer.Enabled = true;" statement is inside "toolStripButton1_Click" events. if you want your timer should work just after program loads, then put this statement "timer.Enabled = true;" in "Form1_Load" event.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1