基本信息
源码名称:C#简单的抽奖
源码大小:3.29M
文件格式:.zip
开发语言:C#
更新时间:2016-01-12
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 1 元×
微信扫码支付:1 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
一款简单的抽奖,帮助初学者
一款简单的抽奖,帮助初学者
public partial class Form1 : Form
{
Point mouseOff;//鼠标移动位置变量
bool leftFlag;//标记是否为左键
private const int CS_DropSHADOW = 0x20000;
private const int GCL_STYLE = (-26);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int SetClassLong(IntPtr hwnd, int nIndex, int dwNewLong);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int GetClassLong(IntPtr hwnd, int nIndex);
int time = 5;//倒计时
int loc = 0;//数组下标
int num = 38;//随机数最大值
string[] arr_name = new string[] { "刘召星", "宋光明", "胡龙辉", "胡龙军", "刘军辉", "郭林浩", "王星辉", "霍佳敏", "高春元", "杨青龙", "张航", "灿毛", "南宝山", "冯瑞", "闵浩", "孙鑫", "汪显鹏", "马旭龙", "王永康", "薛豪", "张鹏飞", "王豪", "杨金龙", "唐乾银", "毛彦杰", "李鹏鹏", "王高磊", "刘子敏", "申轩", "陈丽", "罗贤芬", "余田", "康国梁", "任仲伟", "熊嘉威", "余春彬", "段李博", "王凯"};
public Form1()
{
InitializeComponent();
SetClassLong(this.Handle, GCL_STYLE, GetClassLong(this.Handle, GCL_STYLE) | CS_DropSHADOW);
}
private void butStart_Click(object sender, EventArgs e)
{
butStart.Enabled = false;
timerBut.Enabled = true;
butStart.Text = "抽奖中(5)";
timerName.Enabled = true;
labName.ForeColor = Color.Yellow;
this.pictureBox1.Visible = false;
this.pictureBox2.Visible = false;
this.pictureBox3.Visible = false;
this.pictureBox4.Visible = false;
this.pictureBox5.Visible = false;
}
private void timerBut_Tick(object sender, EventArgs e)
{
time--;
butStart.Text = "抽奖中(" time ")";
if (time == -1)
{
labName.Text = "恭喜" arr_name "!";
butStart.Text = "抽奖";
butStart.Enabled = true;
timerBut.Enabled = false;
timerName.Enabled = false;
labName.ForeColor = Color.Red;
time = 5;
pictureBox1.Enabled = true;
this.pictureBox1.Visible = true;
pictureBox2.Enabled = true;
this.pictureBox2.Visible = true;
pictureBox3.Enabled = true;
this.pictureBox3.Visible = true;
pictureBox4.Enabled = true;
this.pictureBox4.Visible = true;
pictureBox5.Enabled = true;
this.pictureBox5.Visible = true;
//抽完一次覆盖该名称
for (int i = loc; i < arr_name.Length - 1; i )
{
arr_name[i] = arr_name[i 1];
}
num--;//随机数范围-1
}
}
private void timerName_Tick(object sender, EventArgs e)
{
Random ra = new Random();
loc = ra.Next(num);
labName.Text = arr_name[loc];
}
private void labName_TextChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
this.Close();
}
private void Form1_VisibleChanged(object sender, EventArgs e)
{
}
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
mouseOff = new Point(-e.X, -e.Y); //得到变量的值
leftFlag = true; //点击左键按下时标注为true;
}
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (leftFlag)
{
Point mouseSet = Control.MousePosition;
mouseSet.Offset(mouseOff.X, mouseOff.Y); //设置移动后的位置
Location = mouseSet;
}
}
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
if (leftFlag)
{
leftFlag = false;//释放鼠标后标注为false;
}
}
}
}