| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2593 人关注过本帖
标题:求助:我的Timer好象启动不了
取消只看楼主 加入收藏
yanhaolang
Rank: 1
等 级:新手上路
帖 子:60
专家分:7
注 册:2007-3-12
收藏
 问题点数:0 回复次数:2 
求助:我的Timer好象启动不了
public partial class Form1 : Form
    {
        int flag = 1;
        Label lab1 ;
        char[] randchar;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            randchar = new char[52];
            for (int i = 0; i < 26; i++)
            {
                randchar[i] = (char)('a' + i);
               
            }
            for (int i = 26; i < 52; i++)
            {
                randchar[i] = (char)('A' + i - 26);
               
            }   
            
  

        }
        #region 随机生成label
        private void createLab()
        {
            lab1 = new Label();
            Random rand = new Random();
            int randNum= rand.Next(52);
            this.lab1.Text = randchar[randNum].ToString();
            lab1.ForeColor = Color.Red;
            lab1.BackColor = Color.Transparent;
            lab1.Font = new Font("黑体", 18);
            Point p = new Point(rand.Next(0,this.Width), 0);
            this.lab1.Location=p;
            lab1.AutoSize = true;
            this.Controls.Add(lab1);
            Thread td = new Thread(new ThreadStart(movedown));
            td.Start();
        }
        void movedown()
        {
            while (true)
            {
                Point p = new Point(this.lab1.Location.X, this.lab1.Location.Y + 1);
                this.lab1.Location = p;
                this.timer1.Enabled = false;
                if (this.lab1.Location.Y == this.Height)
                {
                   this.timer1.Enabled = true;
                    this.lab1.Dispose();
                    break;                  
                }    //这之后好象 没有触发timer事件,都没有字母掉掉下来,createLab()不执行 ?为什么呢     

                if (flag == 0)
                    break;
               

            }
           // this.lab1.Location.Y = this.lab1.Location.Y + 1;
        }
        #endregion
        string s = "";
        private void timer1_Tick(object sender, EventArgs e)
        {
            createLab();
         
        }      
        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            flag = 0;
        }   


    }
搜索更多相关主题的帖子: Timer int randchar public 
2008-04-10 14:40
yanhaolang
Rank: 1
等 级:新手上路
帖 子:60
专家分:7
注 册:2007-3-12
收藏
得分:0 
你把 代码复制过去,你 做个窗体 就可以调试啊,我的问题是 timer启动不了,
干脆不用 timer ,用多线程 做就不会有问题。。
2008-04-10 15:46
yanhaolang
Rank: 1
等 级:新手上路
帖 子:60
专家分:7
注 册:2007-3-12
收藏
得分:0 
调试过,设置断点跟踪,监视变量,那里没有问题,而且 this.timer1.Enabled = true 执行了,但是 就是不产生字母往下掉。。。
2008-04-11 09:32
快速回复:求助:我的Timer好象启动不了
数据加载中...
 
   



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

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