日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Winform小软件 —— 摇奖机

發布時間:2024/3/24 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Winform小软件 —— 摇奖机 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Winform小軟件 —— 搖獎機

?

代碼 using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Text;
using?System.Windows.Forms;
using?System.Threading;

namespace?搖獎機
{
????
public?partial?class?Form1?:?Form
????{
????????
public?Form1()
????????{
????????????InitializeComponent();
????????????Control.CheckForIllegalCrossThreadCalls?
=?false;
????????????
????????????
//Form的相關“屬性”設置:
????????????this.FormBorderStyle?=?FormBorderStyle.None;
????????????
this.TransparencyKey?=?Color.Yellow;?//將某顏色設置為透明
????????????this.BackgroundImage?=?new?Bitmap("Images/Transball.bmp");
????????}

????????
bool?isFormMove?=?false;?//是否移動
????????int?x,?y;????????//獲得鼠標初始位置

????????
//鼠標按下
????????private?void?Form1_MouseDown(object?sender,?MouseEventArgs?e)
????????{
????????????
if?(e.Button?==?MouseButtons.Left)
????????????{
????????????????isFormMove?
=?true;
????????????????x?
=?e.X;
????????????????y?
=?e.Y;
????????????}
????????}
????????
//鼠標移動
????????private?void?Form1_MouseMove(object?sender,?MouseEventArgs?e)
????????{
????????????
if?(isFormMove)
????????????{
????????????????
//獲得鼠標當前位置
???????????????Point?p?=?Form.MousePosition;
???????????????
//鼠標當前位置?-?鼠標初始位置?=?窗體要移動的位置
???????????????this.Location?=?new?Point(p.X?-?x,?p.Y?-?y);
????????????}
????????}
????????
//鼠標釋放
????????private?void?Form1_MouseUp(object?sender,?MouseEventArgs?e)
????????{
????????????isFormMove?
=?false;
????????}


????????
/*
?????????*?問題:
?????????*?在Form里加了一個Button后,Form的KeyPress事件在按下Enter鍵時就不能觸發了?
?????????*?解決方案:
?????????*?重寫該方法實現,擴展ProcessDialogKey方法調用Form1_KeyPress事件?
*/
????????
protected?override?bool?ProcessDialogKey(Keys?keyData)
????????{
????????????
if?(keyData?==?Keys.Return)
????????????{
????????????????
//this.KeyPreview?=?true;
????????????????KeyPressEventArgs?myKeyPressEventArgs?=?new?KeyPressEventArgs(Convert.ToChar(keyData));
????????????????Form1_KeyPress(
this,?myKeyPressEventArgs);
????????????}
????????????
return?base.ProcessDialogKey(keyData);
????????}

????????
int?n?=?1;
????????Thread?thread1,?thread2,?thread3,?thread4,?thread5,?thread6;
????????
????????
//按鍵事件
????????private?void?Form1_KeyPress(object?sender,?KeyPressEventArgs?e)
????????{
????????????
if?(n?%?2?==?1)
????????????{
????????????????n
++;
????????????????thread1?
=?new?Thread(randomLabelText);
????????????????thread1.Start(
this.label1);
????????????????thread1.Join(
10);?//讓別的線程停止

????????????????thread2?
=?new?Thread(randomLabelText);
????????????????thread2.Start(
this.label2);
????????????????thread2.Join(
5);?//讓別的線程停止

????????????????thread3?
=?new?Thread(randomLabelText);
????????????????thread3.Start(
this.label3);
????????????????thread3.Join(
7);

????????????????thread4?
=?new?Thread(randomLabelText);
????????????????thread4.Start(
this.label4);
????????????????thread4.Join(
14);

????????????????thread5?
=?new?Thread(randomLabelText);
????????????????thread5.Start(
this.label5);
????????????????thread5.Join(
3);

????????????????thread6?
=?new?Thread(randomLabelText);
????????????????thread6.Start(
this.label6);
????????????????thread6.Join(
13);

????????????}
????????????
else
????????????{
????????????????thread1.Abort();?thread2.Abort();?thread3.Abort();
????????????????thread4.Abort();?thread5.Abort();?thread6.Abort();

????????????????label7.Text?
=?"中獎號碼:"?+?label1.Text?+?"??"?+?label2.Text?+?"??"?+?label3.Text;
????????????????label7.Text?
+=?"??"?+?label4.Text?+?"??"?+?label5.Text?+?"??"?+?label6.Text;
????????????????n
--;
????????????}
????????}

????????
//產生隨機數給Label控件
????????private?void?randomLabelText(object?obj)
????????{
????????????Label?lb?
=?obj?as?Label;
????????????Random?rand?
=?new?Random();
????????????
while?(true)
????????????{
????????????????
int?i?=?rand.Next(0,?10);
????????????????lb.Text?
=?i.ToString();
????????????????Thread.Sleep(
100);
????????????}
????????}

????????
private?void?button1_MouseClick(object?sender,?MouseEventArgs?e)
????????{
????????????Application.Exit();
????????}
????}
}

?

作者:?XuGang ??網名:鋼鋼
出處:?http://xugang.cnblogs.com
聲明:?本文版權歸作者和博客園共有!轉載時必須保留此段聲明,且在文章頁面明顯位置給出原文連接。

轉載于:https://www.cnblogs.com/stevenjson/archive/2012/04/17/2454598.html

總結

以上是生活随笔為你收集整理的Winform小软件 —— 摇奖机的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。