System.Timers.Timer - 编程新手,需要帮助 [英] System.Timers.Timer -- new to programming, need help

查看:94
本文介绍了System.Timers.Timer - 编程新手,需要帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

帮助!我是Visual Basic .Net(2002版)的新手,我正试图获得一个

System.Timers.Timer来为我工作,显示一个大约两个的启动画面

秒然后加载主窗体。我有两种形式(frmSplash和

frmMain)和一个代码模块设置作为我的启动对象。


这是我的代码,当我尝试运行这部分启动

屏幕表单显示然后程序终止。我做错了什么?


谢谢,


凯文


***** ********************************************* ***** ******


模块模块1


''声明两个表格

Public myMain As New frmMain()

Public MySplash As new frmSplash()


Public Class StartUp


Public Shared Sub Main( )

''显示启动画面

MySplash.Show()

''创建一个新的Timer,Interval设置为2秒。

Dim aTimer As New System.Timers.Timer(2000)

''添加一个事件处理程序来处理Elapsed time事件

AddHandler aTimer。 Elapsed,AddressOf OnTimedEvent

''只在第一​​次Interval过去时才举起活动。

aTimer.AutoReset = False

''启用计时器

aTimer.Enabled = True

End Sub


Public Shared Sub OnTimedEvent(By Val source As Object,_

ByVal e

As System.Timers.ElapsedEventArgs)

''显示主窗体并隐藏启动画面

myMain.Show()

MySplash.Hide()

End Sub


结束班


结束模块

Help! I am new to Visual Basic .Net (version 2002) and I am trying to get a
System.Timers.Timer to work for me to display a splash screen for about two
seconds and then load the main form. I have two forms (frmSplash and
frmMain) and a code Module setup as my startup object.

Here is the code that I have, when I try to run this part of the splash
screen form shows and then program terminates. What am I doing wrong?

Thanks,

Kevin

************************************************** ***********

Module Module1

'' Declare the two forms
Public myMain As New frmMain()
Public MySplash As New frmSplash()

Public Class StartUp

Public Shared Sub Main()
'' Show the splash screen
MySplash.Show()
'' Create a new Timer with Interval set to 2 seconds.
Dim aTimer As New System.Timers.Timer(2000)
'' Add an event handler to handle the Elapsed time event
AddHandler aTimer.Elapsed, AddressOf OnTimedEvent
'' Only raise the event the first time Interval elapses.
aTimer.AutoReset = False
'' Enable the timer
aTimer.Enabled = True
End Sub

Public Shared Sub OnTimedEvent(ByVal source As Object, _
ByVal e
As System.Timers.ElapsedEventArgs)
'' Show the main form and hide the splash screen
myMain.Show()
MySplash.Hide()
End Sub

End Class

End Module

推荐答案




In你的子主要显示启动画面并设置一个计时器。

完成后,程序结束,因为没有别的

它可以做。将计时器放在启动画面中并将其关闭

自我2秒后。尝试这样的事情。


公共共享主要()

''显示启动画面

MySplash.TopMost = True

MySplash.Show()

Application.Run(frmMain)

End Sub

Ken


" WhiteSocksGuy" < Wh是*********** @ earthlink.net>在留言中写道

新闻:e0 ************** @ TK2MSFTNGP10.phx.gbl ...
Hi,

In your sub main you show the splash screen and set up a timer.
Once it is done doing that the program ends because there is nothing else
for it to do. Place the timer in the splash screen and have it close it
self after 2 seconds. Try something like this.

Public Shared Sub Main()
'' Show the splash screen
MySplash.TopMost = True
MySplash.Show()
Application.Run(frmMain)
End Sub
Ken

"WhiteSocksGuy" <wh***********@earthlink.net> wrote in message
news:e0**************@TK2MSFTNGP10.phx.gbl...
帮助!我是Visual Basic .Net(2002版)的新手,我正试图获得一个
System.Timers.Timer来为我工作以显示关于两个的启动画面
秒然后加载主窗体。我有两个表单(frmSplash和
frmMain)和一个代码模块设置作为我的启动对象。

这是我有的代码,当我尝试运行这部分启动时<屏幕显示然后程序终止。我做错了什么?

谢谢,

凯文

***************** ********************************* ***********
模块模块1

''声明两种形式
Public myMain As new frmMain()
Public MySplash As new frmSplash()

Public Class启动

Public Shared Sub Main()
''显示启动画面
MySplash.Show()
''创建一个新的Timer,Interval设置为2秒。
Dim aTimer As New System.Timers.Timer(2000)
''添加一个事件处理程序来处理Elapsed time事件
AddHandler aTimer.Elapsed,AddressOf OnTimedEvent
''只有在第一次间隔过去时才举起活动。
aTimer.AutoReset = False
''启用计时器
aTimer.Enabled = True
End Sub
酒吧lic Shared Sub OnTimedEvent(ByVal source As Object,_
ByVal e
As System.Timers.ElapsedEventArgs)
''显示主窗体并隐藏启动画面
myMain.Show ()
MySplash.Hide()
End Sub

End Class

结束模块
Help! I am new to Visual Basic .Net (version 2002) and I am trying to get
a
System.Timers.Timer to work for me to display a splash screen for about
two
seconds and then load the main form. I have two forms (frmSplash and
frmMain) and a code Module setup as my startup object.

Here is the code that I have, when I try to run this part of the splash
screen form shows and then program terminates. What am I doing wrong?

Thanks,

Kevin

************************************************** ***********

Module Module1

'' Declare the two forms
Public myMain As New frmMain()
Public MySplash As New frmSplash()

Public Class StartUp

Public Shared Sub Main()
'' Show the splash screen
MySplash.Show()
'' Create a new Timer with Interval set to 2 seconds.
Dim aTimer As New System.Timers.Timer(2000)
'' Add an event handler to handle the Elapsed time event
AddHandler aTimer.Elapsed, AddressOf OnTimedEvent
'' Only raise the event the first time Interval elapses.
aTimer.AutoReset = False
'' Enable the timer
aTimer.Enabled = True
End Sub

Public Shared Sub OnTimedEvent(ByVal source As Object, _
ByVal e
As System.Timers.ElapsedEventArgs)
'' Show the main form and hide the splash screen
myMain.Show()
MySplash.Hide()
End Sub

End Class

End Module



嗨凯文,


我更喜欢启动画面windows.forms.timer这是为了这个更容易

处理。


不是你应该使用它,但是我有一个来自闪屏的样本

插入,它有更多的绝对是必要但是效果很好。

(虽然它表明它不会阻止你的主变形程序)


我希望这会有所帮助,

Cor

\\\form1

Private frm As New Form2

Private WithEvents timer1 As New Windows.Forms .Tim呃

Private Sub Form1_Load(ByVal发件人_

作为对象,ByVal e As System.EventArgs)_

处理MyBase.Load

timer1.Enabled = True

timer1.Interval = 12500

frm.Show()

End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object,_

ByVal e As System.EventArgs)处理timer1.Tick

timer1.Enabled = False

frm.Close()

frm.Dispose()

End Sub


///

\\\form2


Private WithEvents timer1 As New Windows.Forms.Timer

Private Sub Form2_Load(ByVal sender)作为对象,_

ByVal e As System.EventArgs)处理MyBase.Load

Label1.Text =高我在这里

Me.ForeColor = Color.White

timer1.Enabled = True

timer1.Interval = 125

Me.BackColor = Color.CornflowerBlue

Me.Opacity = 1

Me.TopMost = True

Me.Text = Splash

End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object,_

ByVal e As System.EventArgs)Handles timer1.Tick

Me.Opacity - = 0.01

如果Me.Opacity = 0那么

timer1.Enabled = False

Me.Close()

结束如果

结束子

///
Hi Kevin,

I prefer for a splash screen the windows.forms.timer it is for this easier
to handle.

Not that you should use it, but I have beneath a sample from a splash screen
inserted, it has more in it than absolute is necessary but it works nice.
(While it shows it does not stop your mainform program)

I hope this helps,

Cor
\\\form1
Private frm As New Form2
Private WithEvents timer1 As New Windows.Forms.Timer
Private Sub Form1_Load(ByVal sender _
As Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
timer1.Enabled = True
timer1.Interval = 12500
frm.Show()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles timer1.Tick
timer1.Enabled = False
frm.Close()
frm.Dispose()
End Sub

///
\\\form2

Private WithEvents timer1 As New Windows.Forms.Timer
Private Sub Form2_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Label1.Text = "High I Am Here"
Me.ForeColor = Color.White
timer1.Enabled = True
timer1.Interval = 125
Me.BackColor = Color.CornflowerBlue
Me.Opacity = 1
Me.TopMost = True
Me.Text = "Splash"
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles timer1.Tick
Me.Opacity -= 0.01
If Me.Opacity = 0 Then
timer1.Enabled = False
Me.Close()
End If
End Sub
///
模块模块1

''声明两种形式
Public myMain As new frmMain()
Public MySplash As new frmSplash()

Public Class StartUp

Public Shared Sub Main()
''显示启动画面
MySplash.Show()
''创建一个新的Timer,Interval设置为2秒。
Dim aTimer As New System.Timers.Timer(2000)
''添加一个事件处理程序来处理Elapsed time事件
AddHandler aTimer.Elapsed,AddressOf OnTimedEvent
''只在第一​​次间隔时间内提升事件。
aTimer.AutoReset = False
''启用计时器
aTimer.Enabled = True
End Sub

Public Shared Sub OnTimedEvent(ByVal source As Object,_
ByVal $ b $ as As System.Timers.ElapsedEventArgs)
''显示主窗体并隐藏启动画面
myMain .Show()
MySplash.Hide()
End Sub

End Class

结束模块
Module Module1

'' Declare the two forms
Public myMain As New frmMain()
Public MySplash As New frmSplash()

Public Class StartUp

Public Shared Sub Main()
'' Show the splash screen
MySplash.Show()
'' Create a new Timer with Interval set to 2 seconds.
Dim aTimer As New System.Timers.Timer(2000)
'' Add an event handler to handle the Elapsed time event
AddHandler aTimer.Elapsed, AddressOf OnTimedEvent
'' Only raise the event the first time Interval elapses.
aTimer.AutoReset = False
'' Enable the timer
aTimer.Enabled = True
End Sub

Public Shared Sub OnTimedEvent(ByVal source As Object, _
ByVal e As System.Timers.ElapsedEventArgs)
'' Show the main form and hide the splash screen
myMain.Show()
MySplash.Hide()
End Sub

End Class

End Module


*" Cor" < no*@non.com> scripsit:
* "Cor" <no*@non.com> scripsit:
我更喜欢使用启动画面windows.forms.timer,这样可以更轻松地处理。


ACK。

不是你应该使用它,但是我在插入的闪屏下面有一个样本,它有更多的内容绝对是必要的,但它工作得很好。
(虽然它表明它不会停止你的mainform程序)
I prefer for a splash screen the windows.forms.timer it is for this easier
to handle.
ACK.
Not that you should use it, but I have beneath a sample from a splash screen
inserted, it has more in it than absolute is necessary but it works nice.
(While it shows it does not stop your mainform program)




我会把定时器用于关闭在

闪屏上闪屏,以避免紧耦合。


-

Herfried K. Wagner [MVP]

< http://dotnet.mvps.org/>

网站地址已更改!



I would place the timer used for closing the splash screen on the
splash screen in order to avoid tight coupling.

--
Herfried K. Wagner [MVP]
<http://dotnet.mvps.org/>
Website Address Changed!


这篇关于System.Timers.Timer - 编程新手,需要帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆