触摸时如何让图片框显示消息框

时间:2017-04-26 08:46:31

标签: c# visual-studio

    private void GameScreen_Load(object sender, EventArgs e)
    {

    }

    public void timer1_Tick(object sender, EventArgs e)
    {
        int Time = 1;
        timer1.Start();
        timer1.Interval = 1;
        Time += 1;

    }

    private void Character_Click(object sender, KeyEventArgs e)
    {

    }

    private void pictureBox1_Click(object sender, EventArgs e)
    {

    }

    private void GameScreen_KeyDown(object sender, KeyEventArgs e)
    {
         int x = CharacterUser.Location.X;
         int y = CharacterUser.Location.Y;

        if (e.KeyCode == Keys.Right) x += 4;
        else if (e.KeyCode == Keys.Left) x -= 4;

        CharacterUser.Location = new Point(x, y);
    }

    public void Block_Click(object sender, EventArgs e)
    {
        timer1.Stop();
    }
    private void IsTouching(PictureBox CharacterUser, PictureBox Block)
    {
        if (CharacterUser.Location.X + CharacterUser.Width < Block.Location.X)
            MessageBox.Show("Continue? You survived for", +Time, "You failed", MessageBoxButtons.YesNo);
        if (Block.Location.X + Block.Width < CharacterUser.Location.X)
            MessageBox.Show("Continue? You survived for", +Time, "You failed", MessageBoxButtons.YesNo);
        if (CharacterUser.Location.Y + CharacterUser.Height < Block.Location.Y)
            MessageBox.Show("Continue? You survived for", +Time, "You failed", MessageBoxButtons.YesNo);
        if (Block.Location.Y + Block.Height < CharacterUser.Location.Y)
            MessageBox.Show("Continue? You survived for", +Time, "You failed", MessageBoxButtons.YesNo);

    }


    }
}

我不确定为什么当我使用GameScreen_KeyDown中的代码移动其中一个图片框以便它触摸另一个图片框时,不会出现消息框而且不会识别出计时器在消息文本中,即使我在timer1_Tick中定义了它,也会非常感谢任何帮助。

提前致谢!

0 个答案:

没有答案