Public C護(hù)激篙刻蕻灸戈熏恭抹lass Form1
成都創(chuàng)新互聯(lián)專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于成都網(wǎng)站設(shè)計、成都做網(wǎng)站、岳陽縣網(wǎng)絡(luò)推廣、成都小程序開發(fā)、岳陽縣網(wǎng)絡(luò)營銷、岳陽縣企業(yè)策劃、岳陽縣品牌公關(guān)、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運(yùn)營等,從售前售中售后,我們都將竭誠為您服務(wù),您的肯定,是我們最大的嘉獎;成都創(chuàng)新互聯(lián)為所有大學(xué)生創(chuàng)業(yè)者提供岳陽縣建站搭建服務(wù),24小時服務(wù)熱線:18980820575,官方網(wǎng)址:www.cdcxhl.com
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim c As Char
c = Trim(TextBox3.Text)
Select Case c
Case "+"
TextBox4.Text = Val(TextBox1.Text) + Val(TextBox2.Text)
Case "-"
TextBox4.Text = Val(TextBox1.Text) - Val(TextBox2.Text)
Case "*"
TextBox4.Text = Val(TextBox1.Text) * Val(TextBox2.Text)
Case "\"
If Val(TextBox2.Text) = 0 Then
MsgBox("分母為0")
Else
TextBox4.Text = Val(TextBox1.Text) \ Val(TextBox2.Text)
End If
Case "/"
If Val(TextBox2.Text) = 0 Then
MsgBox("分母為0")
Else
TextBox4.Text = Val(TextBox1.Text) / Val(TextBox2.Text)
End If
End Select
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
End
End Sub
End Class
using?System;
using?System.Windows.Forms;
namespace?WindowsFormsApplication1
{
public?partial?class?Form1?:?Form
{
Timer?tm?=?new?Timer();//實例化?timeer?
static?int?timeS?=?0;?//設(shè)置靜態(tài)變量記錄秒數(shù)
TimeSpan?ts?=?new?TimeSpan();?//實例化?TimeSpan?
public?Form1()
{
InitializeComponent();
}
private?void?button1_Click(object?sender,?EventArgs?e)
{
tm.Interval?=?1000;?//設(shè)置?timeer?1000毫秒執(zhí)行一次
tm.Tick?+=?new?EventHandler(timeer_Tick);?//設(shè)置?timeer?運(yùn)行事件
tm.Start();?//?啟用?timeer
}
private?void?timeer_Tick(object?sender,?EventArgs?e)
{
timeS?+=?1;?//秒數(shù)?+1?
ts?=?new?TimeSpan(0,?0,?timeS);?
label1.Text?=?ts.Hours?+?":"?+?ts.Minutes?+?":"?+?ts.Seconds;
}
private?void?button2_Click(object?sender,?EventArgs?e)
{
tm.Stop();
timeS?=?0;
}
}
}
最近在網(wǎng)上搜索了一些關(guān)于實現(xiàn)關(guān)機(jī) 重啟 注銷的文章 發(fā)現(xiàn)大多介紹的是VB NET 用API實現(xiàn)這些功能 且在XPsp 環(huán)境下無法正常的關(guān)機(jī)與注銷 而對于VB NET 的介紹幾乎沒有 本文章所涉及的知識點有
用實現(xiàn)關(guān)機(jī) 重啟 注銷功能 通過使用textbox與timer控件的結(jié)合編寫定時器功能 為你的程序加上超鏈接
本篇文章具有一定的基礎(chǔ)性和廣泛的實用性 相信能夠給 初學(xué)者帶來一定的幫助
本文所使用的編程環(huán)境是Microsoft Visual Studio 首先打開 Visual Studio 在文件 (File) 菜單上 單擊新建項目 (New Project) 在新建項目 (New Project) 對話框的模板 (Templates) 窗格中 單擊 Windows 應(yīng)用程序 (Windows Application) 單擊確定 (OK)
具體步驟如下
首先在Form 窗體上添加一個Label 控件屬性text設(shè)置為:今天: 然后分別添加 個button控件name分別為button button button 它們的text屬性分別為 關(guān)閉計算機(jī)(啟動定時器) 注銷 重新啟動
圖
現(xiàn)在我們就需要為程序加上一個定時器了 這個定時器需要與textbox 控件相關(guān)聯(lián) 輸入正確時間格式后就可以啟動定時功能了 然后我們需要在窗體上添加一個timer 一個textbox 控件 和一個RadioButton 控件 讓它們保留默認(rèn)值不變 其中 TextBox 控件的text屬性設(shè)置為 : : RadioButton 控件text設(shè)置為 指定時間關(guān)機(jī)|時間格式 小時: 分鐘: 秒如圖 所示
圖
以上界面工作基本完成現(xiàn)在需要輸入代碼了
雙擊窗體進(jìn)入常規(guī) 聲明Public Class Form 事件中
CODE
Imports System Runtime InteropServicesImports Microsoft VisualBasicPublic Class Form _ 調(diào)用系統(tǒng)參數(shù)Friend Shared Function GetCurrentProcess() As IntPtrEnd Function
_Friend Shared Function OpenProcessToken(ByVal h As IntPtr
ByVal acc As Integer ByRef phtok As IntPtr) As BooleanEnd Function
_Friend Shared Function LookupPrivilegeValue(ByVal host As String
ByVal name As String ByRef pluid As Long) As BooleanEnd Function
_Friend Shared Function AdjustTokenPrivileges(ByVal htok As IntPtr
ByVal disall As Boolean ByRef newst As TokPriv Luid
ByVal len As Integer ByVal prev As IntPtr
ByVal relen As IntPtr) As BooleanEnd Function
_Friend Shared Function ExitWindowsEx(ByVal flg As Integer
ByVal rea As Integer) As BooleanEnd Function
Friend Const SE_PRIVILEGE_ENABLED As Integer = H Friend Const TOKEN_QUERY As Integer = H Friend Const TOKEN_ADJUST_PRIVILEGES As Integer = H Friend Const SE_SHUTDOWN_NAME As String = SeShutdownPrivilege Friend Const EWX_LOGOFF As Integer = H 注銷計算機(jī)Friend Const EWX_SHUTDOWN As Integer = H 關(guān)閉計算機(jī)Friend Const EWX_REBOOT As Integer = H 重新啟動計算機(jī)Friend Const EWX_FORCE As Integer = H 關(guān)閉所有進(jìn)程 注銷計算機(jī)Friend Const EWX_POWEROFF As Integer = H Friend Const EWX_FORCEIFHUNG As Integer = H
_ 引用參數(shù) Friend Structure TokPriv Luid Public Count As Integer Public Luid As Long Public Attr As IntegerEnd Structure
Private Shared Sub DoExitWin(ByVal flg As Integer) Dim xc As Boolean 判斷語句 Dim tp As TokPriv Luid Dim hproc As IntPtr = GetCurrentProcess() 調(diào)用進(jìn)程值 Dim htok As IntPtr = IntPtr Zero xc = OpenProcessToken(hproc TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY htok) tp Count = tp Luid = tp Attr = SE_PRIVILEGE_ENABLED xc = LookupPrivilegeValue(Nothing SE_SHUTDOWN_NAME tp Luid) xc = AdjustTokenPrivileges(htok False tp IntPtr Zero IntPtr Zero) xc = ExitWindowsEx(flg )End Sub
Public Shared Sub Reboot() DoExitWin((EWX_FORCE Or EWX_REBOOT)) 重新啟動計算機(jī)End Sub
Public Shared Sub PowerOff() DoExitWin((EWX_FORCE Or EWX_POWEROFF)) 關(guān)閉計算機(jī)End Sub
Public Shared Sub LogoOff() DoExitWin((EWX_FORCE Or EWX_LOGOFF)) 注銷計算機(jī)End Sub
Dim entTime As Object 保存輸入時間Dim xianzaiTime As Object 保存實時時間Dim startTime As Object 保存開始定時時間
注銷button 按鈕輸入code
Private Sub Button _Click(ByVal sender As System Object
ByVal e As System EventArgs) Handles Button ClickLogoOff() 注銷計算機(jī)End Sub
雙擊重新啟動按鈕button 輸入code
Private Sub Button _Click(ByVal sender As System Object
ByVal e As System EventArgs) Handles Button Click
Reboot()
End Sub
雙擊關(guān)閉計算機(jī)按鈕button 輸入code
Private Sub Button _Click(ByVal sender As System Object
ByVal e As System EventArgs) Handles Button Click startTime = TimeOfDay If Not IsDate(TextBox Text) Then 用IsData函數(shù)判斷輸入的時間格式MsgBox( 你所輸入的不是時間格式 ! 錯誤 ) ElseentTime = TimeValue(TextBox Text) End If Timer Enabled = True 啟動定時器 Me WindowState = System Windows Forms FormWindowState Minimized 最小化窗體
End Sub
如圖
圖
雙擊timer 控件如圖
圖
輸入代碼
Private Sub Timer _Tick(ByVal sender As System Object
ByVal e As System EventArgs) Handles Timer Tick xianzaiTime = TimeOfDay If RadioButton Checked Then
If DateDiff(Microsoft VisualBasic DateInterval Second
xianzaiTime entTime) Then 用DateDiff函數(shù)判斷是否到時間了
End IfEnd If
PowerOff() 關(guān)閉計算機(jī)End Sub
好了 基本上一個定時關(guān)機(jī)程序就完成了 接下來加一個超級鏈接吧!當(dāng)然對于高手來說可能是廢話 但是對于新手來說這也是必備的 這個超級鏈接當(dāng)然是我們最喜歡的天極網(wǎng)開發(fā)頻道了
先創(chuàng)建一個Label控件吧 把它托到窗體上 將text屬性設(shè)置為天極網(wǎng)開發(fā)頻道如圖
圖
接下來需要輸入代碼了 雙擊窗體Form
進(jìn)入Public Class Form 事件
代碼
Private Declare Function ShellExecute Lib shell dll
Alias ShellExecuteA (ByVal hwngnd As Integer
ByVal lpOperation As String ByVal lpFile As String
ByVal lpParameters As String ByVal lpDirectory As String
ByVal nShowCmd As Integer) As Integer
如圖
圖
雙擊剛才添加的label屬性text:(天極網(wǎng)開發(fā)頻道)中輸入以下代碼
Private Sub Label _Click(ByVal sender As System Object
ByVal e As System EventArgs) Handles Label ClickShellExecute( open CStr( ) CStr( ) )
End SubEnd Class
OK!全部搞定 按F 鍵運(yùn)行如圖 所示 選擇相應(yīng)選項后點擊(關(guān)閉計算機(jī)啟動定時器按鈕)就可以了 現(xiàn)在程序?qū)凑漳闼O(shè)定的時間而啟動關(guān)閉計算機(jī)選項
lishixinzhi/Article/program/net/201311/12366