Senin, 11 Juli 2016

Cara Membuat Form Loading Keren di Visual Basic

Berikut ini adalah kode dan tutorial yang disertai video bagaimana cara membuat form loading keren menggunakan Visual Basic VB.NET. Untuk membuatnya anda membutuhkan 1 buah form dan satu buah module untuk mendeklarasikan MyFont, untuk lebih jelasnya anda dapat mendownload project dan melihat video tutorialnya.
Kode Form:

Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Label1.Font = myfont.GetInstance(72, FontStyle.Bold)
    End Sub
    Private Sub TLOAD_Tick(sender As Object, e As EventArgs) Handles TLOAD.Tick
        Dim i As Double
        Static ictr As Integer
        For i = 1 To 100
            Label1.Text = ProgressBar1.Value
        Next
        If ictr <= 100 Then
            ProgressBar1.Value = ictr
            ictr = ictr + 1
        Else
            'FORM_UTAMA.Show() 'Ini Merupakan Form yang Akan Muncul Setelah Form Loading Selesai
            'Form_Login.Hide() 'Untuk Menyembunyikan Form Login
            Me.Close() 'Menutup Form Loading atau Form Ini
        End If
    End Sub
End Class
Kode MyFont:

Kode myfont:
Imports System.Drawing.Text
Imports System.Runtime.InteropServices
Module myfont
    '
    '' Start ==[Authors Line]==
    '' This tutorial by SkyArs (www.skyars.com)
    '' Don't remove this line for legal purposes
    '' End ====[Authors Line]====
    '
    'PRIVATE FONT COLLECTION TO HOLD THE DYNAMIC FONT
    Private _pfc As PrivateFontCollection = Nothing
    Public ReadOnly Property GetInstance(ByVal Size As Single,
                                         ByVal style As FontStyle) As Font
        Get
            'IF THIS IS THE FIRST TIME GETTING AN INSTANCE
            'LOAD THE FONT FROM RESOURCES
            If _pfc Is Nothing Then LoadFont()

            'RETURN A NEW FONT OBJECT BASED ON THE SIZE AND STYLE PASSED IN
            Return New Font(_pfc.Families(0), Size, style)

        End Get
    End Property
    Private Sub LoadFont()
        Try
            'INIT THE FONT COLLECTION
            _pfc = New PrivateFontCollection

            'LOAD MEMORY POINTER FOR FONT RESOURCE
            Dim fontMemPointer As IntPtr =
                Marshal.AllocCoTaskMem(
                My.Resources.digital_7.Length)

            'COPY THE DATA TO THE MEMORY LOCATION
            Marshal.Copy(My.Resources.digital_7,
                         0, fontMemPointer,
                         My.Resources.digital_7.Length)

            'LOAD THE MEMORY FONT INTO THE PRIVATE FONT COLLECTION
            _pfc.AddMemoryFont(fontMemPointer,
                               My.Resources.digital_7.Length)

            'FREE UNSAFE MEMORY
            Marshal.FreeCoTaskMem(fontMemPointer)
        Catch ex As Exception
            'ERROR LOADING FONT. HANDLE EXCEPTION HERE
        End Try
    End Sub
End Module

Download Project:
Download Project
Lihat Video:

0 komentar:

Posting Komentar

Kita bukanlah apa-apa tanpaNya, jika ada pertanyaan mengenai artikel silakan tinggalkan komentar anda melalui form komentar :)

SkyArs Corp. © 2016. Tweaked by: Soni Sitez Powered by: Blogger