网上搜索,很多都是说子窗口传值到父窗口,我现在为了实现webbrowser的自定义下载,前面的功夫都做到了,就差如何做个下载进度指示,之前一直不知道如何解决,后来从其他代码中忽然灵感一现.....
父窗口:Form1中按钮Button1,定时器Timer1
Public Class Form1 Dim f2 As Form2 Dim step1 As Integer = 1 Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Button1.Click Timer1.Enabled = True f2 = New Form2 f2.Show() End Sub Private Sub Timer1_Tick(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Timer1.Tick f2.TextBox1.Text = step1 step1 += 1 If step1 > 20 Then f2.Close() step1 = 1 Timer1.Enabled = False End If End Sub End Class
这里 Dim f2 As Form2 而不是定义为 Dim f2 As Form ,这样就可以直接访问form2中元素。