PERHATIAN

Password semua file download:
"softbimantoro"

Kamis, 10 November 2011

Gradient Background Form

Posted by b_agoy 22.58, under , | No comments


Ingin form aplikasi anda menjadi tampak menarik dengan background gradien color seperti diatas??
Berikut ini akan saya berikan tutornya yah...

VB 6.0

Buatlah sebuah Module baru lalu ketikkan:
Enum GradMode
gmHorizontal = 0
gmVertical = 1
End Enum

Public Function GradientForm(ByVal Frm As Form, ByVal StartColor As Long, ByVal Endcolor As Long, ByVal Mode As GradMode)
Dim Rs As Integer, Gs As Integer, Bs As Integer
Dim Re As Integer, Ge As Integer, Be As Integer
Dim Rk As Single, Gk As Single, Bk As Single
Dim R As Integer, G As Integer, B As Integer
Dim i As Integer, j As Single

On Error Resume Next
Frm.AutoRedraw = True
Frm.ScaleMode = vbPixels

Rs = StartColor And (Not &HFFFFFF00)
Gs = (StartColor And (Not &HFFFF00FF)) \ &H100&
Bs = (StartColor And (Not &HFF00FFFF)) \ &HFFFF&
Re = Endcolor And (Not &HFFFFFF00)
Ge = (Endcolor And (Not &HFFFF00FF)) \ &H100&
Be = (Endcolor And (Not &HFF00FFFF)) \ &HFFFF&

j = IIf(Mode = gmHorizontal, Frm.ScaleWidth, Frm.ScaleHeight)
Rk = (Rs - Re) / j: Gk = (Gs - Ge) / j: Bk = (Bs - Be) / j

For i = 0 To j
R = Rs - i * Rk: G = Gs - i * Gk: B = Bs - i * Bk
If Mode = gmHorizontal Then
Frm.Line (i, 0)-(i - 1, Frm.ScaleHeight), RGB(R, G, B), B
Else
Frm.Line (0, i)-(Frm.ScaleWidth, i - 1), RGB(R, G, B), B
End If
Next
End Function

Untuk menggunakannya ketikkan kode berikut di bagian 'Form_Resize' dari Form:
GradientForm Me, vbRed, vbBlue, 0



VB .NET

Buatlah sebuah Module baru lalu ketikkan:
Public Sub GradientForm(ByVal Frm As Form, ByVal StartColor As Color, ByVal EndColor As Color, ByVal Mode As System.Drawing.Drawing2D.LinearGradientMode)
Dim a As New System.Drawing.Drawing2D.LinearGradientBrush(New RectangleF(0, 0, Frm.Width, Frm.Height), StartColor, EndColor, Mode)
Dim g As Graphics = Frm.CreateGraphics
g.FillRectangle(a, New RectangleF(0, 0, Frm.Width, Frm.Height))
g.Dispose()
End Sub

Untuk menggunakannya tambahkan kode berikut pada Form:
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
GradientForm(Me, Color.Red, Color.Blue, 0)
End Sub

Untuk menggunakannya ketikkan kode berikut di bagian 'Form_Resize' dari Form:
GradientForm(Me, Color.Red, Color.Blue, 0)



DOWNLOAD PROJECT VB 6.0
DOWNLOAD PROJECT VB .NET

0 komentar:

Posting Komentar

Blog Archive

Arsip Blog