Ramadhan ke-4 dan source code sesuai gambar

Alhamdulillah ni udah ramadhan ke-4, pada hari ke-4 ni aku akan memberikan source code dimana form akan mengikuti gambar yang telah kita tentukan, sehingga kita dapat membuat suatu form yang bagus tidak selalu berbentuk kotak akan tetapi bisa sesuai dengan gambar.
Sebagai persiapan anda buat gambar yang bagus ya kemudian disimpan dengan format BMP, mengapa? karena kalau format yang lain akan jelek hasilnya....
kalau udah jangan sediakan rokok, minum karena ni masih ramadhan, kalau buatnya malam ya siapkan aja hehhehhheee
udah persiapannya, buat project baru dengan 1 form, tambahkan picture
kemudian ketikkan kode berikut:


Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long
Private Declare Function SetWindowRgn Lib "user32" (ByVal hwnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
Private Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Const RGN_OR = 2
Dim TeksBerjalan As String

Private Function MakeRegion(picSkin As PictureBox) As Long
Dim X As Long, Y As Long, StartLineX As Long
Dim FullRegion As Long, LineRegion As Long
Dim TransparentColor As Long
Dim InFirstRegion As Boolean
Dim InLine As Boolean
Dim hdc As Long
Dim PicWidth As Long
Dim PicHeight As Long

hdc = picSkin.hdc
PicWidth = picSkin.ScaleWidth
PicHeight = picSkin.ScaleHeight

InFirstRegion = True: InLine = False
X = Y = StartLineX = 0
TransparentColor = GetPixel(hdc, 0, 0)

For Y = 0 To PicHeight - 1
For X = 0 To PicWidth - 1

If GetPixel(hdc, X, Y) = TransparentColor Or X = PicWidth Then
If InLine Then
InLine = False
LineRegion = CreateRectRgn(StartLineX, Y, X, Y + 1)

If InFirstRegion Then
FullRegion = LineRegion
InFirstRegion = False
Else
CombineRgn FullRegion, FullRegion, LineRegion, RGN_OR
DeleteObject LineRegion
End If
End If
Else
If Not InLine Then
InLine = True
StartLineX = X
End If
End If
Next
Next

MakeRegion = FullRegion
End Function



Private Sub Form_Load()
PictureAnimation(0).ScaleMode = vbPixels
PictureAnimation(0).AutoRedraw = True
PictureAnimation(0).AutoSize = True
PictureAnimation(0).BorderStyle = vbBSNone
Me.BorderStyle = vbBSNone
Me.Width = PictureAnimation(0).Width
Me.Height = PictureAnimation(0).Height
Me.Picture = PictureAnimation(0).Picture
WindowRegion = MakeRegion(PictureAnimation(0))
SetWindowRgn Me.hwnd, WindowRegion, True
Me.Refresh

End Sub


udah selesai langsung jalankan.

Posting Komentar