Membuat Shutdown, Restart, Sleep Timer menggunakan visual basic 2008/ vb.net

Thursday, March 6, 2014

Untuk Membuat Shutdown, Restart, Sleep Timer menggunakan visual basic 2008/ vb.net komponen yang dibutuhkan yaitu:

1. 3 label
2. 3 button
3. 2 timer
4. 2 combo box

Kosongkan text pada label1 dan ganti text pada label2 menjadi Jam dan label3 menjadi Opsi, kemudian isikan items pada combobox1 dari angka 1 hingga 23 kemudian dilanjutkan angka 00 dan combobox2 isikan items:
  • Shutdown
  • Restart
  • Sleep
Lalu ganti text dari button menjadi Setting Manual ganti background form menggunakan gambar sesuai keinginan anda saja dan ubah FormBorderStyle menjadi None, ganti Text pada button2 menjadi X dan hapus text pada button3 lihat  gambar dibawah:




Setelah tampilan tertata menjadi seperti yang diatas, kemudian klik 2 kali formnya dan hapus semua kode yang ada lalu masukkan kode dibawah:
Imports System.IO
Public Class Form1
    Private IsFormBeingDragged As Boolean = False
    Private MouseDownX As Integer
    Private MouseDownY As Integer

    Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles MyBase.MouseDown

        If e.Button = MouseButtons.Left Then
            IsFormBeingDragged = True
            MouseDownX = e.X
            MouseDownY = e.Y
        End If
    End Sub

    Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As MouseEventArgs) Handles MyBase.MouseUp

        If e.Button = MouseButtons.Left Then
            IsFormBeingDragged = False
        End If
    End Sub

    Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles MyBase.MouseMove

        If IsFormBeingDragged Then
            Dim temp As Point = New Point()

            temp.X = Me.Location.X + (e.X - MouseDownX)
            temp.Y = Me.Location.Y + (e.Y - MouseDownY)
            Me.Location = temp
            temp = Nothing
        End If
    End Sub
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Label1.Text = "Jam Sekarang  " & TimeOfDay
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
           Dim file As String = "srst.exe"
        Dim dir As Object = Path.GetFullPath(file)
        Dim reg As Object = CreateObject("WScript.Shell")
        reg.regWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\srst", dir)
        Timer2.Enabled = True
        NotifyIcon1.Visible = True
        Me.Hide()
    End Sub

    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        If ComboBox1.Text = "" Then
            Timer2.Stop()
            MsgBox("Anda belum setting jam!!", MsgBoxStyle.Critical, "Error!!")

        ElseIf Hour(TimeOfDay) = ComboBox1.Text Then
            If ComboBox2.Text = "Shutdown" Then
                Shell("Shutdown -s")
                Timer2.Enabled = False
            ElseIf ComboBox2.Text = "Restart" Then
                Shell("Shutdown -r")
                Timer2.Enabled = False
            ElseIf ComboBox2.Text = "Sleep" Then
                Shell("Shutdown -l")
                Timer2.Enabled = False

            End If
        Else
        End If
    End Sub

    Private Sub ContextMenuStrip1_Opening(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles ContextMenuStrip1.Opening
        NotifyIcon1.Visible = False
        Me.Show()
    End Sub

    Private Sub NotifyIcon1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles NotifyIcon1.DoubleClick
        NotifyIcon1.Visible = False
        Me.Show()
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        End
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Left = 1
        Me.Top = 1
        Me.TopMost = True
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        NotifyIcon1.Visible = True
        Me.Hide()
    End Sub
End Class
 


Share this article :

1 comment:

Komentar Terbaru

 
Support : Creating Website | Johny Template | Mas Template
Copyright © 2011. artikel visual basic - All Rights Reserved
Template Created by Creating Website Inspired by Sportapolis Shape5.com
Proudly powered by Blogger