关于vb.net倒计时关闭的信息

vb.net怎么倒计时关闭窗口 就是我要它 还有15秒关闭form1 怎么能加什么控件吗?

加一个计时器控件Timer1

成都创新互联公司专注于越城网站建设服务及定制,我们拥有丰富的企业做网站经验。 热诚为您提供越城营销型网站建设,越城网站制作、越城网页设计、越城网站官网定制、小程序设计服务,打造越城网络公司原创品牌,更为您提供越城网站排名全网营销落地服务。

代码如下:

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Timer1.Interval = 15000

Timer1.Start()

MessageBox.Show("程序将在15s后关闭.")

End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

Me.Dispose()

End Sub

vb 设定时间倒计时关机代码?

在窗体上添加一个Timer控件,一个CommandButton按钮,一个TextBox控件,然后复制下面代码:

Dim

dTime

As

Long

Private

Sub

Form_Load()

Timer1.Interval

=

1000

Timer1.Enabled

=

False

End

Sub

Private

Sub

Command1_Click()

dTime

=

CInt(Text1.Text)

Timer1.Enabled

=

True

End

Sub

Private

Sub

Timer1_Timer()

dTime

=

dTime

-

1

If

dTime

=

Then

Shell

"C:\WINDOWS\system32\shutdown.exe

-s

-f

-t

0"

'调用系统关机命令

End

Sub

VB.net如何设置msgbox可以定时自动关闭?

MessageBox里的Show里没有自动关闭的方法,但是你可以自定义一个MessageBox,MessageBox就是一个窗体,你新建一个窗体Form2,添加一个public属性message和一个定时器timer1,timer1的interval设置成你想要的时间,在Form2的Load事件启动timer1,Timer1_Tick事件里关闭窗口Me.Close(),然后在需要显示Messagebox的时候,在主窗口Form1里设置messge属性,然后用show方法弹出窗口就可以了。

Form1程序:(添加了一个Button1)

Public Class Form1

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

Dim f2 As Form2 = New Form2

f2.Message = "提示"

f2.ShowDialog()

End Sub

End Class

Form2程序:(添加了一个Label1显示信息和一个Timer1用于计时,Form2可以自定义成你想要的样式,标题,按钮,窗体样式等)

Public Class Form2

'自定义属性 显示提示信息

Public WriteOnly Property Message As String

Set(value As String)

Label1.Text = value

End Set

End Property

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick

Me.Close()

End Sub

Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load

Timer1.Interval=3000 '定时3秒关闭窗口

Timer1.Enabled = True

End Sub

End Class

代码已在VS2017测试通过。


文章名称:关于vb.net倒计时关闭的信息
分享路径:http://ybzwz.com/article/doggopd.html