Form Berlatar Gradien
Kode berikut ini akan mengubah latar Form menjadi kombinasi warna secara gradien.
[ VB 6.0 ]
Buat sebuah Module baru dan 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
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 ]
Buat sebuah Module baru dan 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
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 di Form :
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
GradientForm(Me, Color.Red, Color.Blue, 0)
End Sub
GradientForm(Me, Color.Red, Color.Blue, 0)
End Sub
Dan di bagian 'Form_Resize'-nya ketikkan :
GradientForm(Me, Color.Red, Color.Blue, 0)
Label: (Menengah), Form, VB .NET, VB 6.0
0 Komentar:
Posting Komentar
Pengunjung yang baik selalu meninggalkan jejak berupa komentar. :)
Berlangganan Posting Komentar [Atom]
<< Beranda