16,553
社区成员
发帖
与我相关
我的任务
分享
Imports System.Threading
Imports System.ComponentModel
Public Class Form1
Dim g2 As Graphics
Dim xp1 As Bitmap = New Bitmap("d:\1.bmp")
Dim xp2 As Bitmap = New Bitmap("d:\112.bmp")
Dim bgimage As Bitmap
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
bgimage = New Bitmap(PictureBox1.Width, PictureBox1.Height) '创建相同大小的内存位图
g2 = Graphics.FromImage(bgimage)
PictureBox1.Image = bgimage
'g2.DrawImage(My.Resources.tr, 0, 0)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim t1 As New Thread(AddressOf thread1)
Dim isy As ISynchronizeInvoke = Me
t1.Start(isy)
End Sub
Private Sub thread1(ByVal obj As Object)
Dim isy As ISynchronizeInvoke = obj
isy.BeginInvoke(New MethodInvoker(AddressOf work), Nothing)
End Sub
Public bolSwitch As Boolean = False
Public Sub work()
For a As Integer = 1 To 10000000
bolSwitch = Not bolSwitch
If bolSwitch = True Then
g2.DrawImage(xp1, 20, 20)
Else
g2.DrawImage(xp2, 20, 20)
End If
g2.DrawString(Guid.NewGuid.ToString, SystemFonts.CaptionFont, Brushes.Blue, 40, 40)
PictureBox1.Invalidate()
'PictureBox1.Image = bgimage
Thread.Sleep(1)
Application.DoEvents()
Next
End Sub
End Class