Uygun olduğu bölümler :
Vb.net - vb 2010-12
Vb.net - vb 2010-12
Kod:
[COLOR="Yellow"][B]Public Shared Sub DrawDropShadow(G As Graphics, color As Color, pth As GraphicsPath, size As Integer, Optional Angle As Single = 120, Optional Distance As Single = 0, Optional Opacity As Single = 1, Optional Spread As Single = 2)
' Trim the angle
If Angle > 360 Then Angle = 360 * (Angle / 360 - Math.Floor(Angle / 360))
If Angle < 0 Then Angle = 360 * (Angle / 360 - Math.Floor(Angle / 360))
If Distance < 0 Then Throw New Exception("Uzaklık 0'dan yüksek olmalı") ' Ters uzaklıklar istemeyiz dimi ;)
If Opacity < 0 Or Opacity > 1 Then Throw New Exception("Şeffaflık 0 ile bir arasında")
Dim pthCopy As GraphicsPath = pth.Clone ' Yolu Kopyala (klon)
size *= 2 ' Normalil 2 katı yap ki pixel seviyesinde gölge oluşsun
' Hesaplayıp uzaklığı ayarlıyoruz
Dim xi As Double = Math.Cos((Math.PI / 180) * (Angle - 90)) * Distance
Dim yi As Double = Math.Sin((Math.PI / 180) * (Angle - 90)) * Distance
If Distance > 0 Then pthCopy.Transform(New Matrix(1, 0, 0, 1, xi, yi))
'Yolun içi yerine bir kesimi ayarlıyoruz..
Dim OldClip As Region = G.Clip
Dim NewClip As GraphicsPath = pth.Clone
Dim b = NewClip.GetBounds
NewClip.Transform(New Matrix((b.Width - 1) / b.Width, 0, 0, (b.Height - 1) / b.Height, 0.5, 0.5)) ' Shrink it a pixle to make sure the visible shadow don't get clipped
NewClip.AddRectangle(New RectangleF((b.X - size) * 2, (b.Y - size) * 2, (b.Width + size) * 2, (b.Height + size) * 2)) ' Invert it
G.SetClip(NewClip)
'Gölgeyi Çizer
For i = 0 To size
b = pthCopy.GetBounds
Using m As New Matrix((b.Width + 1) / b.Width, 0, 0, (b.Height + 1) / b.Height, -0.5, -0.5)
Using br As New SolidBrush(color.FromArgb((((255 - Math.Pow(i / size, 1 + Spread) * 255) * Opacity) / size), color))
pthCopy.Transform(m)
G.FillPath(br, pthCopy)
End Using
End Using
Next
' Temizler
pthCopy.Dispose()
NewClip.Dispose()
If OldClip IsNot Nothing Then G.Clip = OldClip Else G.ResetClip()
End Sub[/B][/COLOR]
Son düzenleme: