以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  如何刷新界面的上的内容?  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=157066)

--  作者:lur320
--  发布时间:2020/9/30 9:41:00
--  如何刷新界面的上的内容?

http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=152101&authorid=0&page=0&star=1

 

我按照这个帖子里面的做了一个等待界面。但是我想定期刷新里面的内容,请问怎么做?

代码是

 

Public delimgng As image =GetImage("bei.png")

Private waitMess As New System.Windows.Forms.Form()

Private sFlog As Boolean = True
Private Sub ShowWaitMess()
Dim waitMesspic As New System.Windows.Forms.PictureBox()
Dim waitMesspic2 As New System.Windows.Forms.TextBox()
waitMesspic.Image = System.Drawing.Image.FromFile(ProjectPath & "Images\\timg2.gif")
waitMesspic.Dock = System.Windows.Forms.DockStyle.fill
waitMesspic.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom

waitMesspic2.text=Vars("loadingtext")  我想定期刷新这个,而Vars("loadingtext") 是在内部函数里面变化。
waitMesspic2.AutoSize=True
waitMesspic2.BackColor = Color.white
waitMesspic2.top = 70
waitMesspic2.left = 40
waitMesspic2.Font = new Font("weiruanyahei",10.25,FontStyle.Regular)

waitMess.Controls.Add(waitMesspic2)
waitMess.Controls.Add(waitMesspic)
waitMesspic2.BringToFront()

waitMess.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
waitMess.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
waitMess.TransparencyKey = Color.red
waitMess.OPacity = 0.9
waitMess.Width = 328  \'固定大小
waitMess.Height = 120

Try
    If Not waitMess.IsDisposed Then
        waitMess.ShowDialog()
    End If
Catch Err As System.Threading.ThreadAbortException
    MessageBox.Show(Err.Message)
End Try
End Sub


Public Sub WaitShow()
Try
    If sFlog = True Then
        sFlog = False
        Dim upgradeThread As System.Threading.Thread = Nothing
        upgradeThread = New System.Threading.Thread(New System.Threading.ThreadStart(AddressOf ShowWaitMess))
        upgradeThread.Start()

    End If
Catch Err As System.Threading.ThreadAbortException
    MessageBox.Show(Err.Message)
End Try
End Sub


Private Delegate Sub CloseFormDelegate()
Public Sub WaitClose()
If waitMess.InvokeRequired Then
    waitMess.Invoke(New CloseFormDelegate(AddressOf DoCloseJob))
Else
    DoCloseJob()
End If
End Sub


private Sub DoCloseJob()
Try
    If Not waitMess.IsDisposed Then
        sFlog = True
        waitMess.Close()
    End If
Catch Err As System.Threading.ThreadAbortException
    MessageBox.Show(Err.Message)
End Try
End Sub

 

 

内部函数

 

WaitShow()  \'打开
Dim ik As Integer
Do
ik+=1
Vars("loadingtext") ="请等待" & ik
Loop While ik <= 1000000

WaitClose()  \'关闭

Return Nothing

 

 

请帮忙看下这个怎么改。

 


--  作者:有点蓝
--  发布时间:2020/9/30 10:11:00
--  
比较麻烦,涉及到线程之间的通信。没时间搞
--  作者:lur320
--  发布时间:2020/9/30 10:55:00
--  

那帮忙看看thread 能不能sleep几秒钟后重新刷新窗口?此时loadingtext已经在主线程变化。

代码怎么改?

Public Sub WaitShow()
Try
    If sFlog = True Then
        sFlog = False
        Dim upgradeThread As System.Threading.Thread = Nothing
        upgradeThread = New System.Threading.Thread(New System.Threading.ThreadStart(AddressOf ShowWaitMess))
        upgradeThread.Start()

upgradeThread.sleep(3000)

waitMess刷新?

    End If
Catch Err As System.Threading.ThreadAbortException
    MessageBox.Show(Err.Message)
End Try
End Sub


--  作者:有点蓝
--  发布时间:2020/9/30 11:11:00
--  
还是需要涉及到线程之间的通信,没那么简单
--  作者:lur320
--  发布时间:2020/9/30 14:44:00
--  

试了好几个方式,都不会搞。timer也貌似有问题不知道怎么处理,

如果用do loop消耗太大直接卡死

 

Try
    If Not waitMess.IsDisposed Then
        waitMess.ShowDialog()

do loop 修改lable 的值,没法做到每几秒更新一次,要么直接卡死。

 

试了timer,不会用。


    End If
Catch Err As System.Threading.ThreadAbortException
    MessageBox.Show(Err.Message)
End Try
End Sub