LBSALE[1]LBSALE[watermark]http://www.thysea.com/lb/cgi-bin/topic.cgi?forum=127&topic=1869&show=0
在上述贴子中提到的问题,那种方法虽然可以解决但总是觉得别扭!通过几天的努力,如今我用VB.net可以更方便的控制。以托盘的形式显示,实现代码非常简单,本次源码予于公布:
Public Class Form1
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If My.Computer.Network.IsAvailable = False Then
MessageBox.Show(vbCrLf & "您的计算机没有接入Internet,或者没有活动网卡,程序终止!", "→无条件为你⊙程序设计", MessageBoxButtons.OK, MessageBoxIcon.Error)
End
End If
If My.Computer.Network.Ping("192.168.0.1", 1000) = False Then
Dim m = CreateObject("WScript.Shell")
m.Run("shutdown.exe -s -t 60")
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
MessageBox.Show(vbCrLf & "程序已经执行,将以托盘方式显示在任务栏的通知区域!", "→无条件为你⊙程序设计", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Try
If Me.Visible Then Me.Hide()
Me.KeyPreview = True ';注册键盘事件
Me.ShowInTaskbar = False ';在任务栏处不显示窗体
Catch ex As Exception
MessageBox.Show(ex.Message, "出错啦!原因:", MessageBoxButtons.OK, MessageBoxIcon.Error)
End
End Try
End Sub
Private Sub NotifyIcon1_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseDoubleClick
MessageBox.Show(vbCrLf & "恭喜!程序退出成功,欢迎您的使用!", "→无条件⊙制作!", MessageBoxButtons.OK, MessageBoxIcon.Information)
Me.Close()
End Sub
End Class
自动定时扫描“192.168.0.1”,当然也可以加一个TextBox控件用来人机交互,太简单了,不再赘述。VB.net和C#是Microsoft公司力推的Microsoft Visual Studio .NET 2005编程语言,开发环境一样,我想改用C#来编程,调用的类和方法应该是一样,有兴趣的朋友自行处理。[/watermark] |