笔记4

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace TimerEvents
{
    
public partial class Timer : Form
    {
        System.Windows.Forms.Timer t;

        
public Timer()
        {
            InitializeComponent();
        }

        
void t_Tick(object sender, EventArgs e)
        {
            progressBar.Value 
+= 10;

            
if (progressBar.Value >= 100)
                t.Stop();
        }

        
private void Timer_Shown(object sender, EventArgs e)
        {
            t 
= new System.Windows.Forms.Timer();
            t.Interval 
= 1000;
            t.Tick 
+= new EventHandler(t_Tick);
            t.Start();
        }



        
/// <summary>
        
/// Required designer variable.
        
/// </summary>
        private System.ComponentModel.IContainer components = null;

        
/// <summary>
        
/// Clean up any resources being used.
        
/// </summary>
        
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            
if (disposing && (components != null))
            {
                components.Dispose();
            }
            
base.Dispose(disposing);
        }

        
#region Windows Form Designer generated code

        
/// <summary>
        
/// Required method for Designer support - do not modify
        
/// the contents of this method with the code editor.
        
/// </summary>
        private void InitializeComponent()
        {
            
this.progressBar = new System.Windows.Forms.ProgressBar();
            
this.SuspendLayout();
            
// 
            
// progressBar
            
// 
            this.progressBar.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                        
| System.Windows.Forms.AnchorStyles.Left)
                        
| System.Windows.Forms.AnchorStyles.Right)));
            
this.progressBar.Location = new System.Drawing.Point(1211);
            
this.progressBar.Name = "progressBar";
            
this.progressBar.Size = new System.Drawing.Size(26825);
            
this.progressBar.TabIndex = 0;
            
// 
            
// Timer
            
// 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            
this.ClientSize = new System.Drawing.Size(29247);
            
this.Controls.Add(this.progressBar);
            
this.Name = "Timer";
            
this.Text = "Timer";
            
this.Shown += new System.EventHandler(this.Timer_Shown);
            
this.ResumeLayout(false);

        }

        
#endregion

        
private System.Windows.Forms.ProgressBar progressBar;

        
/// <summary>
        
/// The main entry point for the application.
        
/// </summary>
        [STAThread]
        
static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(
false);
            Application.Run(
new Timer());
        }
    }
}
posted @ 2008-04-18 02:58  李涛  阅读(168)  评论(0)    收藏  举报