| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1048 人关注过本帖
标题:刚做的摇奖机
只看楼主 加入收藏
隨訫ωo鎻慾
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2007-6-12
收藏
 问题点数:0 回复次数:0 
刚做的摇奖机

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

namespace WindowsApplication1
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label lb1;
private System.Windows.Forms.Label lb2;
private System.Windows.Forms.Label lb3;
private System.Windows.Forms.Label lb4;
private System.Windows.Forms.Label lb5;
private System.Windows.Forms.Label lb6;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;

Thread[] tArr = new Thread[6];
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
ThreadRunState runState = ThreadRunState.停止;

public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();

for(int i = 0 ; i < tArr.Length; i++)
{
Pro p = new Pro(
GetLb("lb" + (i + 1)) ,
this
);
tArr[i] = new Thread(new ThreadStart(p.Run));
tArr[i].IsBackground = true;
}
}
Label GetLb(string lbName)
{
foreach(Control c in this.Controls)
{
if (c != null && c.Name == lbName)
return (Label)c;
}
return null;
}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
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.lb1 = new System.Windows.Forms.Label();
this.lb2 = new System.Windows.Forms.Label();
this.lb3 = new System.Windows.Forms.Label();
this.lb4 = new System.Windows.Forms.Label();
this.lb5 = new System.Windows.Forms.Label();
this.lb6 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// lb1
//
this.lb1.AutoSize = true;
this.lb1.BackColor = System.Drawing.Color.Transparent;
this.lb1.Location = new System.Drawing.Point(112, 168);
this.lb1.Name = "lb1";
this.lb1.Size = new System.Drawing.Size(18, 26);
this.lb1.TabIndex = 2;
this.lb1.Text = "0";
//
// lb2
//
this.lb2.AutoSize = true;
this.lb2.BackColor = System.Drawing.Color.Transparent;
this.lb2.Location = new System.Drawing.Point(176, 168);
this.lb2.Name = "lb2";
this.lb2.Size = new System.Drawing.Size(18, 26);
this.lb2.TabIndex = 3;
this.lb2.Text = "0";
//
// lb3
//
this.lb3.AutoSize = true;
this.lb3.BackColor = System.Drawing.Color.Transparent;
this.lb3.Location = new System.Drawing.Point(240, 168);
this.lb3.Name = "lb3";
this.lb3.Size = new System.Drawing.Size(18, 26);
this.lb3.TabIndex = 4;
this.lb3.Text = "0";
//
// lb4
//
this.lb4.AutoSize = true;
this.lb4.BackColor = System.Drawing.Color.Transparent;
this.lb4.Location = new System.Drawing.Point(312, 168);
this.lb4.Name = "lb4";
this.lb4.Size = new System.Drawing.Size(18, 26);
this.lb4.TabIndex = 5;
this.lb4.Text = "0";
//
// lb5
//
this.lb5.AutoSize = true;
this.lb5.BackColor = System.Drawing.Color.Transparent;
this.lb5.Location = new System.Drawing.Point(376, 168);
this.lb5.Name = "lb5";
this.lb5.Size = new System.Drawing.Size(18, 26);
this.lb5.TabIndex = 6;
this.lb5.Text = "0";
//
// lb6
//
this.lb6.AutoSize = true;
this.lb6.BackColor = System.Drawing.Color.Transparent;
this.lb6.Location = new System.Drawing.Point(448, 168);
this.lb6.Name = "lb6";
this.lb6.Size = new System.Drawing.Size(18, 26);
this.lb6.TabIndex = 7;
this.lb6.Text = "0";
//
// label1
//
this.label1.AutoSize = true;
this.label1.BackColor = System.Drawing.Color.Transparent;
this.label1.Location = new System.Drawing.Point(192, 56);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(110, 26);
this.label1.TabIndex = 8;
this.label1.Text = "中奖结果:";
//
// label2
//
this.label2.AutoSize = true;
this.label2.BackColor = System.Drawing.Color.Transparent;
this.label2.Location = new System.Drawing.Point(296, 56);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(71, 26);
this.label2.TabIndex = 9;
this.label2.Text = "000000";
//
// label3
//
this.label3.BackColor = System.Drawing.Color.Transparent;
this.label3.Location = new System.Drawing.Point(0, 72);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(48, 40);
this.label3.TabIndex = 10;
this.label3.Click += new System.EventHandler(this.label3_Click);
//
// label4
//
this.label4.BackColor = System.Drawing.Color.Transparent;
this.label4.Location = new System.Drawing.Point(64, 0);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(48, 40);
this.label4.TabIndex = 11;
this.label4.Click += new System.EventHandler(this.label4_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(11, 23);
this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
this.ClientSize = new System.Drawing.Size(492, 215);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.lb6);
this.Controls.Add(this.lb5);
this.Controls.Add(this.lb4);
this.Controls.Add(this.lb3);
this.Controls.Add(this.lb2);
this.Controls.Add(this.lb1);
this.Font = new System.Drawing.Font("宋体", 15F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.Name = "Form1";
this.Text = "Form1";
this.TransparencyKey = System.Drawing.Color.Yellow;
this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseDown);
this.Load += new System.EventHandler(this.Form1_Load);
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 Form1_Load(object sender, System.EventArgs e)
{

}
void SetNum()
{
this.label2.Text =
lb1.Text
+ lb2.Text
+ lb3.Text
+ lb4.Text
+ lb5.Text
+ lb6.Text;

}

private void label3_Click(object sender, System.EventArgs e)
{
if (runState == ThreadRunState.停止)
{
foreach(Thread t in tArr)
t.Start();
runState = ThreadRunState.运行;
}
else if (runState == ThreadRunState.运行)
{
foreach(Thread t in tArr)
t.Suspend();
runState = ThreadRunState.挂起;
SetNum();
}
else if (runState == ThreadRunState.挂起)
{
foreach(Thread t in tArr)
t.Resume();
runState = ThreadRunState.运行;
SetNum();
}
}

private void label4_Click(object sender, System.EventArgs e)
{
this.Close();
Application.Exit();
}

bool down =false;
Point p = new Point(0, 0);
private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
down =true;
p.X = e.X;
p.Y = e.Y;
}

private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (down)
{
Point pScreen = Control.MousePosition;
pScreen.X -= p.X;
pScreen.Y -= p.Y;
this.Location = pScreen;
}
}

private void Form1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
down =false;
}
}
}

搜索更多相关主题的帖子: 摇奖 System using Forms Windows 
2007-06-12 20:47
快速回复:刚做的摇奖机
数据加载中...
 
   



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

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