先判断游戏是不是在运行中,如果是,就结束游戏(关闭游戏进程)
再重新运行
private void GameRun_Click(object sender, System.EventArgs e)
{
 System.Diagnostics.Process.Start(@"d:\\game.exe");
}
是不是这样情况

解决方案 »

  1.   

    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;
    using System.Drawing.Drawing2D;namespace caomin20140718dazi
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
            Random r = new Random();
            int wrong = 0;
            int right = 0;
            float rightRate = 0;        private void Form1_Load(object sender, EventArgs e)
            {
                WindowState = FormWindowState.Maximized;
                panel1.Width = this.Width-button1.Width-50;
                panel1.Height = this.Height * 4 / 5;
                button1.Left = this.Width - button1.Width-30;
                button2.Left = button1.Left;
                button3.Left = button2.Left;        }        private void timer1_Tick(object sender, EventArgs e)
            {
                foreach (Control a in this.panel1.Controls)
                {
                    if (a.GetType().Name == "Label")
                    {
                        if (a.Tag.ToString().Contains("aa"))
                        {
                            a.Top++;
                            if (a.Top > this.panel1.Height)
                            {
                                a.Dispose();
                                wrong++;
                                this.label4.Text = this.wrong.ToString();
                            }
                        }
                        else if (a.Tag.ToString() == "zidan")
                        {
                            a.Top -= 7;
                            foreach (Control d in this.panel1.Controls)
                            {
                                if (d.GetType().Name == "Label" && d.Text == a.Text && d.Tag.ToString() == "aab")
                                {
                                    if (a.Top <= d.Bottom)
                                    {
                                        a.Dispose();
                                        d.Dispose();
                                        right++;
                                        this.label2.Text = this.right.ToString();                                }
                                }
                            }
                        }
                        if ((this.right + this.wrong) == 0)
                        {
                        }
                        else
                        {
                            this.rightRate = this.right * 100 / (this.right + this.wrong);
                            this.label6.Text = this.rightRate.ToString() + "%";                    }
                            
                    }
                }
            }        private void timer2_Tick(object sender, EventArgs e)
            {
                Label a = new Label();
                a.AutoSize = true;
                a.Text = ((char)r.Next(97, 123)).ToString();
                a.Font = new Font("华文彩云", r.Next(15, 40));
                a.ForeColor = Color.FromArgb(r.Next(0, 256), r.Next(0, 256), r.Next(0, 256));
                a.Location = new Point(r.Next(pictureBox1.Width / 2, this.panel1.Width - a.Width), 0);
                a.Tag = "aa";
                this.panel1.Controls.Add(a);
            }        private void Form1_KeyPress(object sender, KeyPressEventArgs e)
            {
                foreach (Control a in this.panel1.Controls)
                {
                    if (a.GetType().Name == "Label" && a.Tag.ToString() == "aa")
                    {
                        if (e.KeyChar.ToString() == a.Text)
                        {
                            a.Tag += "b";
                            Label b = new Label();
                            b.Text = a.Text;
                            b.Font = a.Font;
                            b.ForeColor = a.ForeColor;
                            b.BackColor = a.ForeColor;
                            b.Location = new Point(a.Left, this.panel1.Height - b.Height);
                            b.Size = new Size(20, 25);
                            b.Tag = "zidan";
                            this.panel1.Controls.Add(b);
                            GraphicsPath g = new GraphicsPath();
                            g.AddEllipse(0, 0, b.Width, b.Height);
                            b.Region = new System.Drawing.Region(g);
                            pictureBox1.Location = new Point(a.Left - pictureBox1.Width / 2 + a.Width / 2 - 10, panel1.Height - pictureBox1.Height);
                            break;
                        }
                    }
                }
            }        private void button1_Click(object sender, EventArgs e)
            {
            }        private void button2_Click(object sender, EventArgs e)
            {
               
                
            }        private void button3_Click(object sender, EventArgs e)
            {
                this.Close();
            }        private void button1_MouseClick(object sender, MouseEventArgs e)
            {
                if (button1.Text == "开始游戏")
                {
                    timer1.Start();
                    timer2.Start();
                    button1.Text = "暂停游戏";
                }
                else if (button1.Text == "暂停游戏")
                {
                    timer1.Stop();
                    timer2.Stop();
                    button1.Text = "开始游戏";
                }
            }
        }
    }
    求大神在button写下重新开始游戏,就是游戏在运行,把panel里面的label控件清除,还有label2,label4,label6里的数字清空,谢了
      

  2.   


    //停止计时器
    timer1.Stop();
    timer2.Stop();//清空标签值
    label2.Text = "";
    label4 = "";
    label6 = "";//清空panel1中的所有控件
    //panel1.Controls.Clear();//清空panel1中的所有Label
    foreach (Control item in panel1.Controls.OfType<Label>())
    {
    panel1.Controls.Remove(item);
    }