| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 698 人关注过本帖
标题:如何让lable控件沿窗体四周运动一圈
只看楼主 加入收藏
黎珍利
Rank: 1
等 级:新手上路
帖 子:20
专家分:9
注 册:2012-3-7
结帖率:71.43%
收藏
已结贴  问题点数:20 回复次数:4 
如何让lable控件沿窗体四周运动一圈
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace yundng
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }


        private void button1_Click(object sender, EventArgs e)
        {
            double myWidth = this.ClientSize.Width;
            double myHeight = this.ClientSize.Height;
            int j = 0;
            int k = 0;
            while (j<myWidth)
            {
                label1.Location = new Point(label1.Location.X + 1, label1.Location.Y);
                j++;
            }
            while (k<myHeight)
            {
                label1.Location = new Point(label1.Location.X, label1.Location.Y +1);
                k++;
            }
            while (j>0)
            {
                label1.Location = new Point(label1.Location.X - 1, label1.Location.Y);
                j--;
            }
            while (k > 0)
            {
                label1.Location = new Point(label1.Location.X, label1.Location.Y - 1);
                k--;
            }
        }

  }
    这样写的话,代码错在哪?
搜索更多相关主题的帖子: double class private public 如何 
2012-03-14 11:15
a8451727
Rank: 1
等 级:新手上路
帖 子:238
专家分:5
注 册:2007-5-22
收藏
得分:5 
你这样是不会动的...你的循环只是给他赋了N次值而已
用Timer控件,在它的事件写
label1.Location = new Point(label1.Location.X + 1, label1.Location.Y);

2012-03-14 11:23
lcawen
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:41
专家分:184
注 册:2011-8-11
收藏
得分:0 
可实现四周移动,不过不是以界面的长宽,是自定义的
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication3
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }
        

        private void Form2_Load(object sender, EventArgs e)
        {
           
        }

        private void button1_Click(object sender, EventArgs e)
        {
         


        }
        int i = 0, j = 0, s = 0, t = 0;
        private void timer1_Tick(object sender, EventArgs e)
        {
            
            
            if (i < 200)
            {
                label1.Location = new Point(label1.Location.X + 1, label1.Location.Y);
                i++;
            }
            else
            {
                s = i;
                if (j < 200)
                {
                    label1.Location = new Point(label1.Location.X, label1.Location.Y + 1);
                    j++;
                }
                else
                {
                    t = j;
                    if (s > 0)
                    {
                        label1.Location = new Point(label1.Location.X - 1, label1.Location.Y);
                        s--;
                    }
                    else
                    {
                        if (t > 0)
                        {
                            label1.Location = new Point(label1.Location.X, label1.Location.Y - 1);
                            t--;
                        }
                        else
                        {
                            i=0;
                            j=0;
                            s = 0;
                            t = 0;
                        }
                    }
                    
                }

            }

        }


        
    }
}
2012-03-14 16:43
lcawen
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:41
专家分:184
注 册:2011-8-11
收藏
得分:10 
更正:以下可以实现循环移动
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication3
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }
        

        private void Form2_Load(object sender, EventArgs e)
        {
           
        }

        private void button1_Click(object sender, EventArgs e)
        {
         


        }
        int i = 0, j = 0, s = 0, t = 0;
        private void timer1_Tick(object sender, EventArgs e)
        {
            
            
            if (i < 20)
            {
                label1.Location = new Point(label1.Location.X + 1, label1.Location.Y);
                i++;
                if (i == 20)
                {
                    s = i;
                }
            }
            else
            {
               
                if (j < 20)
                {
                    label1.Location = new Point(label1.Location.X, label1.Location.Y + 1);
                    j++;
                    if (j == 20)
                    {
                        t = j;
                    }
                }
                else
                {
                  
                    if (s > 0)
                    {
      label1.Location = new Point(label1.Location.X - 1, label1.Location.Y);
                        s--;
                    }
                    else
                    {
                        if (t > 0)
                        {
                            label1.Location = new Point(label1.Location.X, label1.Location.Y - 1);
                            t--;
                        }
                        else
                        {
                            i=0;
                            j=0;
                            s = 0;
                            t = 0;
                        }
                    }
                    
                }

            }

        }


        
    }
}
2012-03-14 16:52
woshichen6
Rank: 2
等 级:论坛游民
帖 子:15
专家分:51
注 册:2011-6-14
收藏
得分:5 
你这样  是没有效果的 需要调用TIMER空间
2012-03-19 15:44
快速回复:如何让lable控件沿窗体四周运动一圈
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017095 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved