vb .net 动态创建Timer控件 10
如下面,到底要怎样用代码创建Timer控件?(可以创建Button之类的,就是Timer不行。)PublicClassForm1Publictimer1AsNewTime...
如下面,到底要怎样用代码创建Timer控件?(可以创建Button之类的,就是Timer不行。)
Public Class Form1
Public timer1 As New Timer With {.Enabled = True, .Interval = 100}
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
timer1 = Me.Controls.Add(timer1)
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
End
End Sub
End Class 展开
Public Class Form1
Public timer1 As New Timer With {.Enabled = True, .Interval = 100}
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
timer1 = Me.Controls.Add(timer1)
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
End
End Sub
End Class 展开
1个回答
展开全部
我从来不加到Controls中也能用,大概这个不是从Control继承而来的,所有非可视部件(即组件)估计都不需要add。
追问
我是想要使用代码来添加Timer控件,而不是用鼠标来添加。
追答
我也没有要鼠标添加,不是在窗口上显示的控件Me.Controls.Add 添加的,像下面那样就可以了。
Public WithEvents timer1 As New Timer With {.Enabled = False, .Interval = 100}
Private Sub timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles timer1.Tick
end
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
timer1.Start()
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询