小弟不才,被一个问题难住了。
一个button,初始的text显示“开始”,当按下开始后,此时一个图片在上面移动,这个时候button变成“暂停”,如果再按下“暂停”,则图片停止移动,并且这个时候,按钮变成“继续”,如果再按“继续”,图片就继续移动,而且这个时候按钮又变成“暂停”。
这个应该怎么做???

解决方案 »

  1.   

    可以用一个变量来记录这个button的状态 根据这个状态来判断要给button的text属性赋相应的值
      

  2.   

    你做的是C/S的程序还是B/S的程序!
      

  3.   


     document.getElementById("btn1").value="暂停";
      

  4.   


    private void button3_Click(object sender, EventArgs e)
            {
                if (this.button3.Text == "开始" || this.button3.Text == "继续")
                {
                    this.button3.Text = "暂停";
                }
                else
                {
                    this.button3.Text = "继续";
                }
            }图片就不知道怎么整了
      

  5.   

    LZ你这样问问题别人没法回答你的
    建议你把问题拆成3个分别问
    1. 怎么让图片在form里面运动
    2. 怎么让运动的图片暂停
    3. 怎么用button来控制这个过程
      

  6.   

    我把我已经写好了代码贴出来吧
     public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
            int x, y;       // 坐标
            bool flagx = true;   // 方向朝左
            bool flagy = true;//方向朝下
            bool btn = false; //按钮暂停        private void Form1_Load(object sender, EventArgs e)
            {
                x = this.Width;
                y = 0;
                lblMsg.Location = new Point(x, y);      // 设定lblMsg控件的起始位置
                lblMsg.BackColor = Color.Aqua;       // 设定lblMsg控件的背景色为浅蓝色
                lblMsg.AutoSize = true;              // 设定此控件能依数据调整大小  
                lblMsg.Font = new Font("标准楷体", 20, FontStyle.Bold);
                // 设定控件内的文字为标楷体、大小为20、粗体字
                lblMsg.Text = "XXX";      // 设定所显示的文字
                timer1.Interval = 10;          //' 设定定时器周期为10/1000=0.01秒
                timer1.Enabled = false;        // 定时器
                button1.Text = "开始";         //开始按钮        }        private void timer1_Tick(object sender, EventArgs e)
            {
                lblLocation.Text = " 位置:" + lblMsg.Location.X+","+lblMsg.Location.Y;
                if (flagx)             // 左移
                {
                    x -= 10;
                    lblMsg.Location = new Point(x, y);
                    lblDirection.Text = "目前方向 : 往左移";
                    if (lblMsg.Left <= 0)
                    {
                        flagx = false;    // 右移
                        y += lblMsg.Height;
                    }
                }
                else                   // 右移   
                {
                    x += 10;
                    lblMsg.Location = new Point(x, y);
                    lblDirection.Text = "目前方向 :  往右移 ";
                    if (lblMsg.Left + lblMsg.Width >= this.Width)
                    { 
                        flagx = true;   //左移
                        y += lblMsg.Height;
                    }            }
                if (y+lblMsg.Height >= this.Height)
                {
                    x = this.Width-lblMsg.Width;
                    y = 0;
                    lblMsg.Location = new Point(x, y);
                    
                }
            }
            #region 单击事件
            private void Form1_MouseClick(object sender, MouseEventArgs e)
            {
                lblLocation.Text = e.X + "," + e.Y;        }
            #endregion
            private void button1_Click(object sender, EventArgs e)
            {
                            
            }在button1_Click中应该就是我想要实现的代码(按钮分“开始”“暂停”“继续”,控制lblmsg的移动)