VB.NET小程序实现3D摇奖

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/fengqingtao2008/article/details/44590577

如图1:

   截图1

如图2

   截图2

   界面布局:放置3个标签,一个按钮。

   功能操作:点击开始按钮,进行摇号,再次点击后,停止,显示出号码;

   实现的代码:

Dim IsFlag As Boolean = False '控制开始变量
    ''' <summary>
    ''' 开始按钮
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click

        If IsFlag = False Then
            IsFlag = True
            Me.btnStart.Text = "停止"
            Dim th As New Thread(AddressOf PalyGame)
            th.IsBackground = True  '后台线程
            th.Name = "新线程"
            th.Start()
        Else
            Me.IsFlag = False
            Me.btnStart.Text = "开始"
        End If
    End Sub
    ''' <summary>
    ''' 开始摇奖方法
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub PalyGame()
        Dim rm As New Random
        While (IsFlag)
            Me.lbl1.Text = rm.Next(0, 10).ToString
            Me.lbl2.Text = rm.Next(0, 10).ToString
            Me.lbl3.Text = rm.Next(0, 10).ToString
        End While
    End Sub
    ''' <summary>
    ''' 界面加载事件
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub frmyaojiang_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Control.CheckForIllegalCrossThreadCalls = False
        '获取或设置一个值,该值指示是否捕获对错误线程的调用,这些调用在调试应用程序时访问控件的 System.Windows.Forms.Control.Handle 属性
    End Sub

展开阅读全文

没有更多推荐了,返回首页