مشاهده نسخه کامل : تغیر شکل فرم با عکس های با پسوند gif

18-09-07, 22:06
روی فرم خود کلیک نمایید واین کد را کپی نمایید
Dim WindowRegion As Long

' I set all these settings here so you won't forget
' them and have a non-working demo... Set them in
' design time
picMainSkin.ScaleMode = vbPixels
picMainSkin.AutoRedraw = True
picMainSkin.AutoSize = True
picMainSkin.BorderStyle = vbBSNone
Me.BorderStyle = vbBSNone

Set picMainSkin.Picture = LoadPicture("G:\Visual Basic Source Code 2003\screen_graphics\bitmap_region\22.GIF")

Me.Width = picMainSkin.Width
Me.Height = picMainSkin.Height

WindowRegion = MakeRegion(picMainSkin)
SetWindowRgn Me.hWnd, WindowRegion, True
در قسمت load picture آدرس عکس با پسوند gif را وارد نمایید
یکp ictureboxبه این فرم اضافه نمایید نام picture boxراpicMainSkin بزارید وبه گوشه ی آخر بالا سمت چپ ببرید تاسایه نندازد
روی pictureboxدابل کلیک نمایید در خاصیتmouse down آن این کد را بنویسید

بعد یک ماژول را به پروژه اضفه نمایید و این کد را درآن بنویسید
Option Explicit
Public Declare Function GetPixel Lib "gdi32" (ByVal hDC As Long, ByVal X As Long, ByVal Y As Long) As Long
Public Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
Public Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Public Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Declare Function ReleaseCapture Lib "user32" () As Long
Public Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Public Const RGN_OR = 2
Public Const HTCAPTION = 2
Public Function MakeRegion(picSkin As PictureBox) As Long

' Make a windows "region" based on a given picture box'
' picture. This done by passing on the picture line-
' by-line and for each sequence of non-transparent
' pixels a region is created that is added to the
' complete region. I tried to optimize it so it's
' fairly fast, but some more optimizations can
' always be done - mainly storing the transparency
' data in advance, since what takes the most time is
' the GetPixel calls, not Create/CombineRgn

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 ' Flags whether we are in a non-tranparent pixel sequence
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

' The transparent color is always the color of the
' top-left pixel in the picture. If you wish to
' bypass this constraint, you can set the tansparent
' color to be a fixed color (such as pink), or
' user-configurable
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
' We reached a transparent pixel
If InLine Then
InLine = False
LineRegion = CreateRectRgn(StartLineX, Y, X, Y + 1)

If InFirstRegion Then
FullRegion = LineRegion
InFirstRegion = False
CombineRgn FullRegion, FullRegion, LineRegion, RGN_OR
' Always clean up your mess
DeleteObject LineRegion
End If
End If
' We reached a non-transparent pixel
If Not InLine Then
InLine = True
StartLineX = X
End If
End If

MakeRegion = FullRegion
End Function
موفق باشید از زیادی کد نترسید خیلی آسونه به شرطی که هرچی گفتم انجام بدید