Sytem Timer

18/12/2007 - 10:57 von Matthias Göbel | Report spam
Hallo,

was mach ich hier falsch (wahrscheinlich alles:-)?
Ein Formular mit drei Lables und ein System-Timer.
Es sollten sich die drei Lables bewegen aber es tut sich nichts.

Module Module1
Public sTimer As New System.Timers.Timer()
Public sTimerActive As Boolean

Sub Main()
AddHandler sTimer.Elapsed, AddressOf sTimerEvent
GC.KeepAlive(sTimer) '???
End Sub

Public Sub OnTimedEvent(ByVal source As Object, ByVal e As
Timers.ElapsedEventArgs)
If sTimerActive = True Then Exit Sub
If sTimer.Enabled = False Then Exit Sub
Form1.sTimer_Elapsed()
End Sub
End Module

Public Class Form1
Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
With sTimer
.AutoReset = True : .Interval = 1 : .Enabled = True
End With
End Sub

Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As
System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
With sTimer
.Enabled = False
.Dispose()
End With
End Sub

Public Sub sTimer_Elapsed()
Label1.Left += 1
If Label1.Left + Label1.Width > Me.Width Then Label1.Left = 0
Label2.Left = Label1.Left
Label3.Left = Label1.Left
End Sub
End Class

MfG
Matthias
 

Lesen sie die antworten

#1 Robert Schneider
18/12/2007 - 11:33 | Warnen spam
"Matthias Göbel" schrieb im
Newsbeitrag news:
Hallo,

was mach ich hier falsch (wahrscheinlich alles:-)?
Ein Formular mit drei Lables und ein System-Timer.
Es sollten sich die drei Lables bewegen aber es tut sich nichts.

Module Module1
Public sTimer As New System.Timers.Timer()
Public sTimerActive As Boolean

Sub Main()
AddHandler sTimer.Elapsed, AddressOf sTimerEvent
GC.KeepAlive(sTimer) '???
End Sub

Public Sub OnTimedEvent(ByVal source As Object, ByVal e As
Timers.ElapsedEventArgs)
If sTimerActive = True Then Exit Sub
If sTimer.Enabled = False Then Exit Sub
Form1.sTimer_Elapsed()
End Sub
End Module

Public Class Form1
Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
With sTimer
.AutoReset = True : .Interval = 1 : .Enabled = True
End With
End Sub

Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As
System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
With sTimer
.Enabled = False
.Dispose()
End With
End Sub

Public Sub sTimer_Elapsed()
Label1.Left += 1
If Label1.Left + Label1.Width > Me.Width Then Label1.Left = 0
Label2.Left = Label1.Left
Label3.Left = Label1.Left
End Sub
End Class





Du musst Sub Main() auf jeden Fall mal durch Sub New() ersetzen. Denn Sub
Main wird nicht aufgerufen.

Gruß,
Robert
e-mail: r_.s_chnei_der\wein_gart_ner.com (remove all '_' and replace '\'
with '@')

Ähnliche fragen