Tuesday, May 22, 2012

Visual Basic : Shutdown Otomatis


Shutdown otomatis samadengan set timer kapan kita akan mematikan Laptop atau Komputer
Ikuti langkah berikut ini :

1. Buka Microsoft Visual Basic
2. Pilih New Project
3. Lalu pilih Windows Form Application
3. Buatlah Masing Masing Komponen dibawah ini
   a. form
   b. groupbox
   c. datetime
   d. button
   e. label
   f. timer
   g. contexmenustrip
   h. notify icon

4. Lalu ubah Properties setiap komponen berikut ini
   a. form 1
      - start position = center screen
      - text = shutdown
      - maximize dan minimize box = false
      - form border size = fixedsingle

   b. groupbox
      - text = set timer
      - size
      - backcolor

   c. label
      - text = time

   d. datetime
      - custom format = hh:mm:tt
      - format = custom
      - show up down = true
      - name = DtTime

   e. timer
      - enabled = false
      - interval = 60000

   f. contexmenustrip
      - tambah exit dan view

   g. notifyicon
      - contextmenustrip = contexmenustrip1
      - icon
      - text


      -screenshot


5. Setelah itu masukkan Coding berikut


Public Class Form1
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim p_time As String
        p_time = Format(TimeOfDay, "hh:mm:tt")
        Try
            If p_time = Trim(DtTime.Text) Then
                System.Diagnostics.Process.Start("Shutdown", "/s")
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub


    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click


        If Button2.Text = "Disabled" Then
            DtTime.Enabled = False
            Button2.Text = "Enabled"
            Timer1.Enabled = True
        Else
            DtTime.Enabled = True
            Button2.Text = "Disabled"
            Timer1.Enabled = False
        End If
    End Sub


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me.Opacity = 0%
        Me.ShowInTaskbar = False
    End Sub


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


    Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
        Me.Opacity = 100%
        Me.ShowInTaskbar = True
    End Sub
End Class

SELAMAT MENCOBA!!!

No comments:

Post a Comment