首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

请教子窗体控制父窗体操作的有关问题

2012-02-07 
请问子窗体控制父窗体操作的问题请问:比如form1的一个变量time初始为100,然后在执行其他操作过程中虽timer

请问子窗体控制父窗体操作的问题
请问:
比如form1的一个变量time初始为100,然后在执行其他操作过程中虽timer1 tick自减,当time=60时form1中new 一个form2并show,且stop了timer1,然后在form2种点击按钮要hide form2 并重新start timer1 并使time从60开始继续随timer1 tick自减,要如何做?


谢谢

[解决办法]

窗体1的代码

VB.NET code
Public Class Form1    Dim time As Integer = 100    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick        time = time - 1        If time = 60 Then            Form2.Show()            Timer1.Stop()        End If        TextBox1.Text = time    End Sub    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load        Timer1.Start()    End SubEnd Class
[解决办法]
上面的代码是事先创建好窗体,在程序中显示

下面的代码是在time=60的时候创建一个新的窗体,并且显示

这两个代码我都试过,你可以直接使用
VB.NET code
Public Class Form1    Dim time As Integer = 100    Dim frm2 As Form    Dim buton As Button = New Button    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load        Timer1.Start()        AddHandler buton.Click, AddressOf buton_Click    End Sub    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick        time = time - 1        If time = 60 Then            buton.Text = "button"            frm2 = New Form            frm2.Show()            frm2.Controls.Add(buton)            frm2.Controls(0).Top = 50            frm2.Controls(0).Left = 50            Timer1.Stop()        End If        TextBox1.Text = time    End Sub    Private Sub buton_Click(ByVal sender As Object, ByVal e As System.EventArgs)        Timer1.Start()        frm2.Hide()    End SubEnd Class 

热点排行