Chinaunix首页 | 论坛 | 博客
  • 博客访问: 111328
  • 博文数量: 48
  • 博客积分: 2210
  • 博客等级: 大尉
  • 技术积分: 540
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-16 17:59
文章分类

全部博文(48)

文章存档

2010年(1)

2009年(15)

2008年(32)

我的朋友

分类: C/C++

2008-07-02 10:18:09

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Threading;
namespace game
{
 ///
 /// Form1 的摘要说明。
 ///

 public class Form1 : System.Windows.Forms.Form
 {
  private System.Windows.Forms.MainMenu mainMenu1;
  private System.Windows.Forms.MenuItem menuItem1;
  private System.Windows.Forms.MenuItem menuItem2;
  private System.Windows.Forms.MenuItem menuItem3;
  private System.Windows.Forms.MenuItem menuItem4;
  private System.Windows.Forms.Timer timer1;
  private System.ComponentModel.IContainer components;
  public Form1()
  {
   //
   // Windows 窗体设计器支持所必需的
   //
   InitializeComponent();
   //
   // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
   //
  }
  ///
  /// 清理所有正在使用的资源。
  ///

  protected override void Dispose( bool disposing )
  {
   if( disposing )
   {
    if (components != null)
    {
     components.Dispose();
    }
   }
   base.Dispose( disposing );
  }
  #region Windows 窗体设计器生成的代码
  ///
  /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  /// 此方法的内容。
  ///

  private void InitializeComponent()
  {
   this.components = new System.ComponentModel.Container();
   this.mainMenu1 = new System.Windows.Forms.MainMenu();
   this.menuItem1 = new System.Windows.Forms.MenuItem();
   this.menuItem2 = new System.Windows.Forms.MenuItem();
   this.menuItem3 = new System.Windows.Forms.MenuItem();
   this.menuItem4 = new System.Windows.Forms.MenuItem();
   this.timer1 = new System.Windows.Forms.Timer(this.components);
   //
   // mainMenu1
   //
   this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
                       this.menuItem1});
   //
   // menuItem1
   //
   this.menuItem1.Index = 0;
   this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
                       this.menuItem2,
                       this.menuItem3,
                       this.menuItem4});
   this.menuItem1.Text = "控制";
   //
   // menuItem2
   //
   this.menuItem2.Index = 0;
   this.menuItem2.Text = "开始";
   this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
   //
   // menuItem3
   //
   this.menuItem3.Index = 1;
   this.menuItem3.Text = "停止";
   this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
   //
   // menuItem4
   //
   this.menuItem4.Index = 2;
   this.menuItem4.Text = "关闭";
   this.menuItem4.Click += new System.EventHandler(this.menuItem4_Click);
   //
   // timer1
   //
   this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
   //
   // Form1
   //
   this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
   this.ClientSize = new System.Drawing.Size(292, 270);
   this.Menu = this.mainMenu1;
   this.Name = "Form1";
   this.Text = "Form1";
   this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.Form1_KeyPress);
  }
  #endregion
  ///
  /// 应用程序的主入口点。
  ///

  [STAThread]
  static void Main()
  {
   Application.Run(new Form1());
  }
  private void menuItem4_Click(object sender, System.EventArgs e)
  {
   this.Close ();
  }
  private void timer1_Tick(object sender, System.EventArgs e)
  {
   System.Windows.Forms.Label lbl1 = new System.Windows.Forms.Label();
   //
   // lblzimu
   //
   lbl1.Location = new System.Drawing.Point(200, 100);
   lbl1.Name = "lblzimu";
   lbl1.BackColor = System.Drawing.Color.Transparent;
   Random objRandom = new Random();
   int a = objRandom.Next(255);
   int b = objRandom.Next(255);
   int c = objRandom.Next(255);
   lbl1.ForeColor = System.Drawing.Color.FromArgb(a,b,c);
   lbl1.Location=new System.Drawing.Point(new Random(DateTime.Now.Millisecond).Next(this.Width),60);
   
   lbl1.Text=""+(char)(97+objRandom.Next(25));
   lbl1.Font = new Font("宋体",24);
   lbl1.Size = new System.Drawing.Size(30, 30);
   lbl1.TabIndex = 6;
   this.Controls.Add(lbl1);
   Employee objemployee = new Employee(lbl1,this);
   Thread objThread = new Thread(new ThreadStart(objemployee.move));
   objThread.Start(); 
  }
  private void menuItem2_Click(object sender, System.EventArgs e)
  {
   this.timer1.Enabled =true;
  }
  private void Form1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
  {
   
   string press=""+e.KeyChar;
   foreach(Control con in this.Controls)
   {
    if(press==con.Text)
    {
     this.Controls.Remove(con);
     con.Dispose();
     break;
    }
   }
  }
  private void menuItem3_Click(object sender, System.EventArgs e)
  {
   this.Close ();
  }
  //用这个类来控制线程
  public class Employee
  {
   System.Windows.Forms.Label label1;
   System.Windows.Forms.Form form1;
   //构造函数
   public Employee(System.Windows.Forms.Label lblcanshu,System.Windows.Forms.Form formcanshu)
   {
    this.label1 = lblcanshu;
    this.form1 = formcanshu;
    this.label1.Left += new Random(DateTime.Now.Millisecond*DateTime.Now.Second).Next(form1.Left);
  
   }
   //方法
   public void move()
   {
    while(true)
    {
     this.label1.Top +=1;
     Thread.Sleep(100);
     if(this.label1.Bottom == form1.Bottom)
     {
      Thread.CurrentThread.Abort();
     }
    }
   }
  }
 }
}
阅读(931) | 评论(0) | 转发(0) |
0

上一篇:银行系统sql触发器代码

下一篇:记事本

给主人留下些什么吧!~~