Yang mau Metro Framework nya silahkan download disini
Cara mensettingnya ikuti langkah-langkah nya dibawah:
1. Download dan ekstrak filenya
2. Buka vb.net lalu buat project baru dan form baru
3. Lalu klik dahulu "Enable All Files"nya
4. Di "References" klik kanan lalu "Browser" pilih framework yang sudah di download
5. Setelah di add, lalu kita tambahkan juga untuk tombol-tombolnya
6. Silahkan drag and drop 3 file framework nya ke toolbox "General"
7. Setelah itu Imports Metro framework ke "Designer" form nya.
8. Selesai deh !!!
Langsung saja, buka Visual Basic 2015 nya, lalu buat form login dan form registrasinya, seperti contoh berikut:
Contoh Form Login |
Contoh Form Signup/Registrasi |
Imports System.Data.OleDbModule koneksiPublic connection As OleDbConnectionPublic cmd As OleDbCommandPublic ds As DataSetPublic dr As OleDbDataReaderPublic da As OleDbDataAdapterPublic lokasidata As StringPublic Sub openConnection()lokasidata = "provider=microsoft.jet.oledb.4.0;data source=db_perusahaan.mdb"connection = New OleDbConnection(lokasidata)If connection.State = ConnectionState.Closed Thenconnection.Open()End IfEnd SubEnd Module
Simpan file module, lalu buka form loginnya, dan masukkan script berikut.
Imports System.Data.OleDb
Public Class login
Private Sub
MetroButton4_Click(sender As Object, e As EventArgs)
Me.Close()
End Sub
Private Sub
MetroLink1_Click(sender As Object, e As EventArgs) Handles
MetroLink1.Click
Signup.Show()
End Sub
Private Sub
MetroButton1_Click(sender As Object, e As EventArgs) Handles
MetroButton1.Click
openConnection()
Dim dr As OleDbDataReader
Dim cmd As OleDbCommand
Dim sQL As String
cmd = New OleDbCommand
cmd.CommandType = CommandType.Text
cmd.Connection = connection
If MetroTextBox1.Text = "" Or
MetroTextBox2.Text = "" Then
MsgBox("Username atau Password Tidak Boleh kosong ! ")
MetroTextBox1.Focus()
Exit Sub
Else
sQL = "select * from tbl_login where username='" & MetroTextBox1.Text & "'
and password='" & MetroTextBox2.Text & "' "
cmd.CommandText = sQL
dr = cmd.ExecuteReader()
dr.Read()
If dr.HasRows Then
MsgBox("Login Success !",
vbInformation)
Me.Visible = False
clear()
Home.Show()
Home.MetroLabel2.Text = dr("username")
Else
MsgBox("Username atau Password Salah !")
End If
End If
connection.Close()
cmd.Dispose()
End Sub
Private Sub
login_Load(sender As Object, e As EventArgs) Handles MyBase.Load
openConnection()
da = New OleDb.OleDbDataAdapter("SELECT * FROM
tbl_login", connection)
ds = New DataSet
ds.Clear()
da.Fill(ds, "tbl_login")
da.Dispose()
ds.Dispose()
connection.Close()
End Sub
Private Sub
MetroButton2_Click(sender As Object, e As EventArgs) Handles
MetroButton2.Click
Me.Close()
End Sub
Private Sub clear()
MetroTextBox1.Text = ""
MetroTextBox2.Text = ""
MetroTextBox1.Focus()
End Sub
End Class
Setelah selesai langsung buka form registrasi nya lalu pastekan script berikut:
Imports System.Data.OleDb
Public Class Signup
Public newData As Boolean
Private Sub
MetroButton1_Click(sender As Object, e As EventArgs) Handles
MetroButton1.Click
openConnection()
Dim dr As OleDbDataReader
Dim cmd As OleDbCommand
Dim login As String
If MetroTextBox1.Text = "" Or
MetroTextBox2.Text = "" Or
MetroTextBox3.Text = "" Then
MsgBox("Data Belum Lengkap ! ")
MetroTextBox1.Focus()
Exit Sub
Else
openConnection()
login = "SELECT * FROM tbl_login where username='" & MetroTextBox1.Text & "'"
cmd = New OleDbCommand
cmd.Connection = connection
cmd.CommandText = login
dr = cmd.ExecuteReader()
dr.Read()
If Not
dr.HasRows Then
login = "insert into tbl_login values('" & MetroTextBox1.Text & "','" & MetroTextBox2.Text & "','" & MetroTextBox3.Text & "')"
cmd = New OleDbCommand(login, connection)
cmd.ExecuteReader()
MsgBox("Registrasi Berhasil, Silahkan Login")
Me.Visible = False
Else
MetroTextBox1.Text = ""
MsgBox("Username Sudah Digunakan ! ")
MetroTextBox1.Focus()
End If
cmd.Dispose()
connection.Close()
End If
clear()
End Sub
Private Sub
Signup_Load(sender As Object, e As EventArgs) Handles MyBase.Load
openConnection()
da = New OleDb.OleDbDataAdapter("SELECT * FROM
tbl_login", connection)
ds = New DataSet
ds.Clear()
da.Fill(ds, "tbl_login")
da.Dispose()
ds.Dispose()
connection.Close()
End Sub
Private Sub clear()
MetroTextBox1.Text = ""
MetroTextBox2.Text = ""
MetroTextBox3.Text = ""
MetroTextBox1.Focus()
End Sub
End Class
Setelah itu silahkan coba run dan cek apakah berhasil? kalau tidak silahkan atur kembali dari form_load sampe button/textbox nya supaya bisa me runing programnya. Kalau ada pertanyaan silahkan komen ya.
3 Komentar
Fungsi dispose klw boleh tau apa yah ?
BalasHapusBang mau nanya, kan itu buatnya sama metro framework nah kodenya "metro textbox1.text", saya kan menggunakan VB, itu kodenya tanpa ada metronya ya?langsung textbox1.text?
BalasHapusengga, tinggal pakai langsung yg ada di toolboxnya
Hapus