用Timer控件动态生成随机数问题!在线等,急~~~~~

sg_linfeng 2016-07-22 03:23:07
用VB.net里的Timer控件动态生成随机数,在点击Button2停止Timer控件时,在软件界面中的三个Label会有跳码的现象,很不解,为此,我在网上找了一段截屏的程序在对每次停止Timer控件时,截取屏幕的图,进行对比,发现截屏后,三个Label控件显示的值与软件界面上显示的三个Label的值有时不一致,有时一致的现象,请问各位高手,这是怎么回事呢?
附代码:
Public Class Form1

Private Sub CatchLDDRezult()
Dim p1 As New Point(0, 0)
Dim p2 As New Point(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height)
Dim pic As New Bitmap(p2.X, p2.Y)
Using g As Graphics = Graphics.FromImage(pic)
g.CopyFromScreen(p1, p1, p2)
pic.Save("D:\1.jpg")
End Using
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Enabled = True
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Timer1.Enabled = False
CatchLDDRezult()
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Randomize()
Dim intRndLDid As Integer = Int(Rnd() * 941 + 1)
Dim strRndLDid As String = Format(intRndLDid, "0000")
Label1.Text = strRndLDid

Randomize()
intRndLDid = Int(Rnd() * 941 + 1)
strRndLDid = Format(intRndLDid, "0000")
Label2.Text = strRndLDid

Randomize()
intRndLDid = Int(Rnd() * 941 + 1)
strRndLDid = Format(intRndLDid, "0000")
Label3.Text = strRndLDid

Label4.Text = Now
End Sub
End Class


...全文
1548 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
舉杯邀明月 2016-07-22
  • 打赏
  • 举报
回复
是不是你的 Timer1“周期”设置得太小了,小于18ms?
sg_linfeng 2016-07-22
  • 打赏
  • 举报
回复
软件运行后的界面和截屏后的界面对比

不一致


一致

1,488

社区成员

发帖
与我相关
我的任务
社区描述
VB API
社区管理员
  • API
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧