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

前端之家收集整理的这篇文章主要介绍了VB.NET小程序实现3D摇奖前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

如图1:

如图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
原文链接:https://www.f2er.com/vb/257504.html

猜你在找的VB相关文章