张彦明ID:yanmingzi
233次访问,排名2万外好友1人,关注者1
学术交流是人生上最爽快的事
yanmingzi的文章
原创 8 篇
翻译 0 篇
转载 0 篇
评论 1 篇
最近评论
yanmingzi:生活在这种充满新技术的世界里太美了!
文章分类
收藏
    相册
    phtone
    ts229班望裕山庄春游
    java
    存档
    软件项目交易
    订阅我的博客
    XML聚合  FeedSky
    订阅到鲜果
    订阅到Google
    订阅到抓虾
    订阅到BlogLines
    订阅到Yahoo
    订阅到GouGou
    订阅到飞鸽
    订阅到Rojo
    订阅到newsgator
    订阅到netvibes

    原创 简单的摇奖机收藏

    新一篇: 手写打印机  | 旧一篇: java 的居中显示代码


    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;
    using System.Runtime;
    using System.Threading;


    namespace yjj
    {
     /// <summary>
     /// Form1 的摘要说明。
     /// </summary>
     public class Form1 : System.Windows.Forms.Form
     {
      private System.Windows.Forms.PictureBox btnkai;
      private System.Windows.Forms.PictureBox btntui;
      private System.Windows.Forms.Label L1;
      private System.Windows.Forms.Label L2;
      private System.Windows.Forms.Label L3;
      private System.Windows.Forms.Label L4;
      private System.Windows.Forms.Label L5;
      private System.Windows.Forms.Label L6;
      private System.Windows.Forms.Label label1;

      private Point mouseOffset;
      private Boolean ismousedown = false;
      private bool IfThreadStart;
      Thread T1;
      Thread T2;
      Thread T3;
      Thread T4;
      Thread T5;
      Thread T6;


      private System.ComponentModel.Container components = null;

      public Form1()
      {
       
       InitializeComponent();

       //
       // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
       //
      }

      protected override void Dispose( bool disposing )
      {
       if( disposing )
       {
        if (components != null)
        {
         components.Dispose();
        }
       }
       base.Dispose( disposing );
      }

      #region Windows 窗体设计器生成的代码
      /// <summary>
      /// 设计器支持所需的方法 - 不要使用代码编辑器修改
      /// 此方法的内容。
      /// </summary>
      private void InitializeComponent()
      {
       System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
       this.btnkai = new System.Windows.Forms.PictureBox();
       this.btntui = new System.Windows.Forms.PictureBox();
       this.L1 = new System.Windows.Forms.Label();
       this.L2 = new System.Windows.Forms.Label();
       this.L3 = new System.Windows.Forms.Label();
       this.L4 = new System.Windows.Forms.Label();
       this.L5 = new System.Windows.Forms.Label();
       this.L6 = new System.Windows.Forms.Label();
       this.label1 = new System.Windows.Forms.Label();
       this.SuspendLayout();
       //
       // btnkai
       //
       this.btnkai.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("btnkai.BackgroundImage")));
       this.btnkai.Location = new System.Drawing.Point(7, 81);
       this.btnkai.Name = "btnkai";
       this.btnkai.Size = new System.Drawing.Size(20, 23);
       this.btnkai.TabIndex = 1;
       this.btnkai.TabStop = false;
       this.btnkai.Click += new System.EventHandler(this.btnkai_Click);
       //
       // btntui
       //
       this.btntui.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("btntui.BackgroundImage")));
       this.btntui.Location = new System.Drawing.Point(76, 12);
       this.btntui.Name = "btntui";
       this.btntui.Size = new System.Drawing.Size(17, 19);
       this.btntui.TabIndex = 2;
       this.btntui.TabStop = false;
       this.btntui.Click += new System.EventHandler(this.btntui_Click);
       //
       // L1
       //
       this.L1.BackColor = System.Drawing.Color.Cornsilk;
       this.L1.Font = new System.Drawing.Font("宋体", 21.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
       this.L1.Location = new System.Drawing.Point(110, 168);
       this.L1.Name = "L1";
       this.L1.Size = new System.Drawing.Size(24, 28);
       this.L1.TabIndex = 3;
       this.L1.Text = "1";
       //
       // L2
       //
       this.L2.BackColor = System.Drawing.Color.Cornsilk;
       this.L2.Font = new System.Drawing.Font("宋体", 18F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
       this.L2.Location = new System.Drawing.Point(178, 168);
       this.L2.Name = "L2";
       this.L2.Size = new System.Drawing.Size(24, 28);
       this.L2.TabIndex = 4;
       this.L2.Text = "2";
       //
       // L3
       //
       this.L3.BackColor = System.Drawing.Color.Cornsilk;
       this.L3.Font = new System.Drawing.Font("宋体", 18F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
       this.L3.Location = new System.Drawing.Point(248, 168);
       this.L3.Name = "L3";
       this.L3.Size = new System.Drawing.Size(24, 28);
       this.L3.TabIndex = 5;
       this.L3.Text = "3";
       //
       // L4
       //
       this.L4.BackColor = System.Drawing.Color.Cornsilk;
       this.L4.Font = new System.Drawing.Font("宋体", 18F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
       this.L4.Location = new System.Drawing.Point(312, 168);
       this.L4.Name = "L4";
       this.L4.Size = new System.Drawing.Size(24, 28);
       this.L4.TabIndex = 6;
       this.L4.Text = "4";
       //
       // L5
       //
       this.L5.BackColor = System.Drawing.Color.Cornsilk;
       this.L5.Font = new System.Drawing.Font("宋体", 18F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
       this.L5.Location = new System.Drawing.Point(379, 168);
       this.L5.Name = "L5";
       this.L5.Size = new System.Drawing.Size(24, 28);
       this.L5.TabIndex = 7;
       this.L5.Text = "5";
       //
       // L6
       //
       this.L6.BackColor = System.Drawing.Color.Cornsilk;
       this.L6.Font = new System.Drawing.Font("宋体", 18F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
       this.L6.Location = new System.Drawing.Point(449, 168);
       this.L6.Name = "L6";
       this.L6.Size = new System.Drawing.Size(24, 28);
       this.L6.TabIndex = 8;
       this.L6.Text = "6";
       //
       // label1
       //
       this.label1.BackColor = System.Drawing.Color.LemonChiffon;
       this.label1.Font = new System.Drawing.Font("宋体", 14F, System.Drawing.FontStyle.Bold);
       this.label1.Location = new System.Drawing.Point(297, 12);
       this.label1.Name = "label1";
       this.label1.Size = new System.Drawing.Size(176, 24);
       this.label1.TabIndex = 9;
       this.label1.Text = "中奖号码: 123456 ";
       this.label1.Visible = false;
       //
       // Form1
       //
       this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
       this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
       this.ClientSize = new System.Drawing.Size(496, 213);
       this.Controls.Add(this.label1);
       this.Controls.Add(this.L6);
       this.Controls.Add(this.L5);
       this.Controls.Add(this.L4);
       this.Controls.Add(this.L3);
       this.Controls.Add(this.L2);
       this.Controls.Add(this.L1);
       this.Controls.Add(this.btntui);
       this.Controls.Add(this.btnkai);
       this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
       this.Name = "Form1";
       this.Text = "Form1";
       this.TransparencyKey = System.Drawing.Color.Yellow;
       this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseDown);
       this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseUp);
       this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseMove);
       this.ResumeLayout(false);

      }
      #endregion

      /// <summary>
      /// 应用程序的主入口点。
      /// </summary>
      [STAThread]
      static void Main()
      {
       Application.Run(new Form1());
      }

      //关闭按扭事件
      private void btntui_Click(object sender, System.EventArgs e)
      {
       T1.Abort();
       T2.Abort();
       T3.Abort();
       T4.Abort();
       T5.Abort();
       T6.Abort();
       
       this.Close();
       Application.Exit();
      }
      //鼠标窗体挪动事件
      private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
      {
       mouseOffset = new Point(-e.X, -e.Y);
       ismousedown = true;
      }

      private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
      {
       if (ismousedown)
       {
        Point mousePos = Control.MousePosition;
        mousePos.Offset(mouseOffset.X, mouseOffset.Y);
        Location = mousePos;
       }

      }

      private void Form1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
      {
       if (e.Button == MouseButtons.Left)
       {
        ismousedown = false;
       }
      }

      //开始按扭实践。。。
      private void btnkai_Click(object sender, System.EventArgs e)
      {
       if (IfThreadStart==false)   //线程的状态
       {
        label1.Visible=false;   //隐藏控件
        InThread A1 = new InThread();   //随机数
        A1.SetNumber(L1,1000);
        T1 = new Thread(new ThreadStart(A1.RunInThread));
        T1.Start();      //开始线程

        InThread A2 = new InThread();
        A2.SetNumber(L2,1111);
        T2 = new Thread(new ThreadStart(A2.RunInThread));
        T2.Start();
      
        InThread A3 = new InThread();
        A3.SetNumber(L3,2222);
        T3 = new Thread(new ThreadStart(A3.RunInThread));
        T3.Start();

        InThread A4 = new InThread();
        A4.SetNumber(L4,3333);
        T4 = new Thread(new ThreadStart(A4.RunInThread));
        T4.Start();

        InThread A5 = new InThread();
        A5.SetNumber(L5,4444);
        T5 = new Thread(new ThreadStart(A5.RunInThread));
        T5.Start();

        InThread A6 = new InThread();
        A6.SetNumber(L6,5555);
        T6 = new Thread(new ThreadStart(A6.RunInThread));
        T6.Start();

        IfThreadStart = true;//线程的状态
       }
       else
       {
        T1.Abort(); //终止线程
        T2.Abort();
        T3.Abort();
        T4.Abort();
        T5.Abort();
        T6.Abort();
        IfThreadStart = false;//线程的状态
        label1.Text ="中奖号码:"+L1.Text +L2.Text+L3.Text+L4.Text+L5.Text +L6.Text;   
        label1.Visible=true; //现实控件
       }

      }
      public class InThread
      {
       private Control A;
       private int Seed;

       public void RunInThread()
       {
        Random N = new Random(Seed);
        do
        {
         A.Text = N.Next(0, 10).ToString();//随机数
         Thread.Sleep(100);//线程休眠
        }
        while (true);
       }

       public void SetNumber(Control B, int SeedHere)
       {
        A = B;
        Seed = SeedHere;
       }
      }
     }
    }

    发表于 @ 2008年05月13日 08:59:59|评论(loading...)|编辑

    新一篇: 手写打印机  | 旧一篇: java 的居中显示代码

    评论:没有评论。

    发表评论  


    当前用户设置只有注册用户才能发表评论。如果你没有登录,请点击登录
    Csdn Blog version 3.1a
    Copyright © yanmingzi