تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
مقال- أفكار في الجرافكس ..... الجزء الثالث
#1
كاتب الموضوع : silverlight

بسم الله الرحمن الرحيم

السلام عليكم ورحمة الله وبركاته

مقدمـــــة:

في الأجزاء السابقة ناقشنا كيفية الاستفادة من +GDI بأكثر من أسلوب و في الجزء الثاني تحديدا ناقشنا كيفية رسم Glow وفي هذه الجزء سنناقش كيفية رسم Glow بطريقة أخري مختلفة.

ولمن يريد مراجعة الأجزاء السابقة يمكنه مراجعة اللينك التالية:

الجزء الأول : http://vb4arb.com/vb/showthread.php?1175

الجزء الثاني : http://vb4arb.com/vb/showthread.php?1176


الفكرة الثالثة:

رسم Glow بطريقة ثانية مختلفة.

أولا قبل مناقشة كيفية رسم Glow لنناقش بعض الأفكار البسيطة التي ستكون مفيدة بشكل عام لاحقا وسنعطي أمثلة علي ذلك.

من المؤكد أن المهتمين بعمليات الرسم يعلمون جيدا كيف يرسمون مستطيلا له حواف دائرية لذلك فإن الكود التالي ليس جديدا عليهم

المثال الأول : رسم مستطيل له حواف دائرية


كود :
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
MyBase.OnPaint(e)

' تعريف مستطيل بالأبعاد المناسبة
Dim rect As New Rectangle(10, 10, 100, 100)
' تعريف نصف قطر بشرط عل أن لا يكود دائما أقل من أو يساو صفر
Dim raduis As Integer = 10
' تعريف مسار الرسم
Dim path As New GraphicsPath

' تعريفبعض المتغيرات التي تعبر عن أبعاد المستطيل ومكان بداية المستطيل
Dim x As Integer = rect.X
Dim y As Integer = rect.Y
Dim w As Integer = rect.Width
Dim h As Integer = rect.Height

' رسم قوس في اقصي أعلي يسار المستطيل
path.AddArc(x, y, raduis, raduis, 180.0F, 90.0F)
' رسم قوس في أقصي أعلي يمين المستطيل
path.AddArc(((x + w) - raduis), y, raduis, raduis, 270.0F, 90.0F)
' رسم قوس في اقصي أسفل يمين المستطيل
path.AddArc(((x + w) - raduis), ((y + h) - raduis), raduis, raduis, 0.0F, 90.0F)
' رسم قوس في أقصي اسفل يسار المستطيل
path.AddArc(x, ((y + h) - raduis), raduis, raduis, 90.0F, 90.0F)

' إخفاء التشوهات الناتجة عن الرسم
' لو قمت بإلغاء السطر التالي من الكود ستلاحظ بعض التشوهات في الرسم وتحديدا عند الحواف الدائرية
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias

' في النهاية نرسم المسار بواحدة من الطرق التالية

' الطريقة الأولي
' رسم المسار بإستخدام لون واحد
Using sb As New SolidBrush(Color.Red)
e.Graphics.FillPath(sb, path)
End Using

' الطريقة الثانية
' رسم المسار بإستخدام لونين
Using lgb As New Drawing2D.LinearGradientBrush(rect, Color.DarkRed, Color.Red, 90, True)
e.Graphics.FillPath(lgb, path)
End Using

' الطريقة الثالثة
' رسم المسار باستخدام أكثر من لون
Dim pgb As New Drawing2D.PathGradientBrush(path)
pgb.SurroundColors = New Color() {Color.DarkCyan, Color.RoyalBlue, Color.SteelBlue, Color.Cyan}
pgb.CenterColor = Color.SteelBlue
e.Graphics.FillPath(pgb, path)
path.Dispose()

End Sub
في واقع الأمر إن مقدرة المبرمج علي تحويل أجزاء من الكود الي دوال Functions أو الي روتينات Methods/Sub يجعل الكود اسهل وأقصر وأيضا يمكن الاستفادة من مثل هذه الدوال أو الروتينات بشكل عام في اي برامج وبشكل لا يحتاج فيه المبرمج الي إعادة صياغة وكتابة الكود اكثر من مرة لذلك من الأفضل تحويل الكود أعلاه الي دالة Function

الكود التالي يوضح شكل الكود بعد تحويل جزء منه الي دالة أو أكثر

وستلاحظون أنه قد تم وضع بعض الشروط لكي نتأكد دائما أن نصف القطر لا يقل عن أو يساوي صفرا


كود :
Public Class Form1

Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
MyBase.OnPaint(e)

' تعريف مستطيل بالأبعاد المناسبة
Dim rect As New Rectangle(10, 10, 100, 100)
' تعريف مسار الرسم
Dim path As GraphicsPath = GetRoundedPath(rect, 10)

' إخفاء التشوهات الناتجة عن الرسم
' لو قمت بإلغاء السطر التالي من الكود ستلاحظ بعض التشوهات في الرسم وتحديدا عند الحواف الدائرية
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias

' في النهاية نرسم المسار بواحدة من الطرق التالية

' الطريقة الأولي
' رسم المسار بإستخدام لون واحد
Using sb As New SolidBrush(Color.Red)
e.Graphics.FillPath(sb, path)
End Using

' الطريقة الثانية
' رسم المسار بإستخدام لونين
Using lgb As New Drawing2D.LinearGradientBrush(rect, Color.DarkRed, Color.Red, 90, True)
e.Graphics.FillPath(lgb, path)
End Using

' الطريقة الثالثة
' رسم المسار باستخدام أكثر من لون
Dim pgb As New Drawing2D.PathGradientBrush(path)
pgb.SurroundColors = New Color() {Color.DarkCyan, Color.RoyalBlue, Color.SteelBlue, Color.Cyan}
pgb.CenterColor = Color.SteelBlue
e.Graphics.FillPath(pgb, path)
path.Dispose()

End Sub

Private Function GetRoundedPath(ByVal rect As Rectangle, _
ByVal TopLeftRaduis As Integer, _
ByVal TopRightRaduis As Integer, _
ByVal BottomLeftRaduis As Integer, _
ByVal BottomRightRaduis As Integer) As GraphicsPath

If ((TopLeftRaduis = 0) OrElse (TopLeftRaduis < 0)) Then
TopLeftRaduis = 1
End If
If ((TopRightRaduis = 0) OrElse (TopRightRaduis < 0)) Then
TopRightRaduis = 1
End If
If ((BottomLeftRaduis = 0) OrElse (BottomLeftRaduis < 0)) Then
BottomLeftRaduis = 1
End If
If ((BottomRightRaduis = 0) OrElse (BottomRightRaduis < 0)) Then
BottomRightRaduis = 1
End If

Dim x As Integer = rect.X
Dim y As Integer = rect.Y
Dim width As Integer = rect.Width
Dim height As Integer = rect.Height
Dim path As New GraphicsPath

path.AddArc(x, y, TopLeftRaduis, TopLeftRaduis, 180.0F, 90.0F)

If (TopRightRaduis <> 1) Then
path.AddArc(((x + width) - TopRightRaduis), y, TopRightRaduis, TopRightRaduis, 270.0F, 90.0F)
Else
path.AddLine((x + width), y, (x + width), width)
End If

If (BottomRightRaduis <> 1) Then
path.AddArc(((x + width) - BottomRightRaduis), ((y + height) - BottomRightRaduis), BottomRightRaduis, BottomRightRaduis, 0.0F, 90.0F)
Else
path.AddLine(CInt((x + width)), CInt((y + height)), CInt((x + width)), CInt((y + height)))
End If

path.AddArc(x, ((y + height) - BottomLeftRaduis), BottomLeftRaduis, BottomLeftRaduis, 90.0F, 90.0F)
path.CloseFigure()

Return path

End Function

Private Function GetRoundedPath(ByVal rect As Rectangle, ByVal radius As Integer) As GraphicsPath
Return GetRoundedPath(rect, radius, radius, radius, radius)
End Function

End Class
المثال الثاني : استخدام الدالة GetRoundedPath لرسم المستطيل بحواف دائرية وبأكثر من أسلوب وفي الكود أدناه تم رسم المستطيل بحيث تكون حوافه اليسري فقط لها شكل دائري



كود :
Public Class Form1

Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
MyBase.OnPaint(e)

' تعريف مستطيل بالأبعاد المناسبة
Dim rect As New Rectangle(10, 10, 100, 100)
' تعريف مسار الرسم
Dim path As GraphicsPath = GetRoundedPath(rect, rect.Width / 2, 0, rect.Width / 2, 0)

' إخفاء التشوهات الناتجة عن الرسم
' لو قمت بإلغاء السطر التالي من الكود ستلاحظ بعض التشوهات في الرسم وتحديدا عند الحواف الدائرية
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias

' رسم المسار بإستخدام لون واحد
Using sb As New SolidBrush(Color.Red)
e.Graphics.FillPath(sb, path)
End Using


End Sub

End Class
يمكنك عزيزي القارئ أن تجرب تمرير قيم الي الدالة بأن تجعل القيم جميعها صفرا أو تجعل بعضها صفرا ولاحظ الفارق في شكل المستطيل وبالتاكيد ليس شرطا أن تكون قيمة نصف القطر متساوية
حيث يمكنك استخدام ارقام مختلفة لنصف القطر


باق الأمثلة والأفكار سيتم عرضها بالمشاركات التالية وفي النهاية سنعطي مثالا لكيفية استخدام هذه الأفكار في بناء شئ يمكن الاستفادة منه

تقبلوا تحياتي
أخوكم عمر
}}}
تم الشكر بواسطة:
#2
المثال الثالث: رسم Glow

لكي نرسم Glow بشكل جيد نحتاج الي تعريف الكثير من المتغيرات والمثال التالي يوضح ذلك ولقد قمت بتوضيح الهدف من كل جزء من الكود داخل المثال


كود :
Public Class Form1

Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
MyBase.OnPaint(e)


' تعريف متغير يعبر عن المستطيل الرئيسي
Dim rect As New Rectangle(20, 20, 100, 25)

' تعريف بعض المستطيلات وربطها جميعها مع المستطيل الرئيسي

' تغير متغير يعبر عن المستطيل الأول بحيث تكون ابعاده مساوية للمستطيل الرئيسي علي ان يكون ارتفاعه يساوي نصف ارتفاع المستطيل الرئيسي
Dim rect1 As New Rectangle(rect.X, rect.Y, rect.Width, (rect.Height / 2))
' تعريف متغير يعبر عن المستطيل الثاني وغالبا هو ما يساوي المستطيل الأول ولكن إرتغاعه يكون اكبر قليلا وبمقدار ضئيل عن إرتفاع المستطيل الأول
Dim rect2 As New Rectangle(rect.X, rect.Y, rect.Width, ((rect.Height / 2) + 1))
' تعريف متغير يعبر عن المستطيل الثالث وستلاحظون هنا أن جزء من أبعادهذا المستطيل ستكون خارج نطاق المستطيل الرئيسي
Dim rect3 As New Rectangle((rect.X - 10), (rect.Y + (rect.Height / 2)), (rect.Width + 20), rect.Height)
' تعريف متغير يعبر عن المستطيل الرابع وهو سيتم رسمه في النصف السفي من المستطيل الرئيسي ولكنه سيزيد بمقدار ضئل جدا في الارتفاع
Dim rect4 As New Rectangle(rect.X, (rect.Y + (rect.Height / 2)), rect.Width, ((rect.Height / 2) + 1))


' تعريف نصف القطر للحواف الدائرية
Dim radius As Integer = 5

' تعريف الألوان المستخدمة لكي نملأ المستطيلات
Dim colorLightLight As Color = Color.LightYellow
Dim colorDarkDark As Color = Color.Orange

Dim colorDark As Color = Color.OrangeRed
Dim colorLight As Color = Color.Yellow

' التأكد من أن الرسم سيحدث بدون تشوهات
Dim mode As SmoothingMode = e.Graphics.SmoothingMode
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias
e.Graphics.SmoothingMode = SmoothingMode.HighQuality

' تعريف متغير يعبر عن Lineargradient Brush
Using lgb As New Drawing2D.LinearGradientBrush(rect1, colorLightLight, colorDarkDark, 90.0F, True)
' تعريف متغير أخر يعبر عن Lineargradient Brush
Using lgb1 As New Drawing2D.LinearGradientBrush(rect1, colorDark, colorLight, -90.0F, True)

' تحديد شكل تدرج اللون في حالة لو كان التدرج أضغر من ابعاد المستطيل
lgb1.WrapMode = WrapMode.TileFlipXY
lgb.WrapMode = WrapMode.TileFlipXY

' تعريف المسار الأول وهو يمثل النصف العلوي من المستطيل الرئيسي وأيضا نجعل حوافه اليسري فقط دائرية
Dim path1 As Drawing2D.GraphicsPath = GetRoundedPath(rect2, radius, radius, 0, 0)
' رسم المسار الأول
e.Graphics.FillPath(lgb, path1)

' تعريف المسار الثاني وهو سيمثل الجزء السفلي من المستطيل
Dim path2 As New GraphicsPath
path2.AddRectangle(rect3)
' تعريف متغير يعبر عن Pathgradient Brush
Dim pgb As New PathGradientBrush(path2)

' إضاف الألوان لهذه الفرشاة
pgb.SurroundColors = New Color() {colorDark, colorDark, colorLight, colorLight}
' تحديد اللون المستخدم للرسم في منتصف المسار وهو الذي سيعمل بمثابة اللون اللامع
pgb.CenterColor = colorLight
' رسم المسار الثاني
e.Graphics.FillPath(pgb, GetRoundedPath(rect4, 0, 0, radius, radius))

End Using
End Using

' رسم الحدود الخارجية للمستطيل

Dim outerBorderColor As Color = Color.DarkOrange
Dim innerBorderColor As Color = Color.Cornsilk

' تعريف متغير يعبر عن مستطيل وستكون ابعاده اقل بمقدا ضئيل عن المستطيل الرئيسي
Dim rect5 As New Rectangle((rect.X + 1), (rect.Y + 1), (rect.Width - 2), (rect.Height - 2))

' رسم الأبعاد الداخلية
Using innerBorderPen As Pen = New Pen(innerBorderColor)
Using path As GraphicsPath = GetRoundedPath(rect5, radius)
e.Graphics.DrawPath(innerBorderPen, path)
End Using
End Using

' رسم أبعاد المستطيل الرئيسي
Using outerBorderPen As Pen = New Pen(outerBorderColor)
Using path As GraphicsPath = GetRoundedPath(rect, radius)
e.Graphics.DrawPath(outerBorderPen, path)
End Using
End Using

e.Graphics.SmoothingMode = mode

End Sub

Private Function GetRoundedPath(ByVal rect As Rectangle, _
ByVal TopLeftRaduis As Integer, _
ByVal TopRightRaduis As Integer, _
ByVal BottomLeftRaduis As Integer, _
ByVal BottomRightRaduis As Integer) As GraphicsPath

If ((TopLeftRaduis = 0) OrElse (TopLeftRaduis < 0)) Then
TopLeftRaduis = 1
End If
If ((TopRightRaduis = 0) OrElse (TopRightRaduis < 0)) Then
TopRightRaduis = 1
End If
If ((BottomLeftRaduis = 0) OrElse (BottomLeftRaduis < 0)) Then
BottomLeftRaduis = 1
End If
If ((BottomRightRaduis = 0) OrElse (BottomRightRaduis < 0)) Then
BottomRightRaduis = 1
End If

Dim x As Integer = rect.X
Dim y As Integer = rect.Y
Dim width As Integer = rect.Width
Dim height As Integer = rect.Height
Dim path As New GraphicsPath

path.AddArc(x, y, TopLeftRaduis, TopLeftRaduis, 180.0F, 90.0F)

If (TopRightRaduis <> 1) Then
path.AddArc(((x + width) - TopRightRaduis), y, TopRightRaduis, TopRightRaduis, 270.0F, 90.0F)
Else
path.AddLine((x + width), y, (x + width), width)
End If

If (BottomRightRaduis <> 1) Then
path.AddArc(((x + width) - BottomRightRaduis), ((y + height) - BottomRightRaduis), BottomRightRaduis, BottomRightRaduis, 0.0F, 90.0F)
Else
path.AddLine(CInt((x + width)), CInt((y + height)), CInt((x + width)), CInt((y + height)))
End If

path.AddArc(x, ((y + height) - BottomLeftRaduis), BottomLeftRaduis, BottomLeftRaduis, 90.0F, 90.0F)
path.CloseFigure()

Return path

End Function

Private Function GetRoundedPath(ByVal rect As Rectangle, ByVal radius As Integer) As GraphicsPath
Return GetRoundedPath(rect, radius, radius, radius, radius)
End Function

End Class

في المشاركة التالية سنقوم بتحويل الكود أعلاه الي دالة أو أكثر من دالة بحيث يسهل استخدامها ولا نحتاج الي تكرار كتابة الكود مرارا وتكرارا وبالتالي يمكن الاستفادة منها بشكل افضل


تقبلوا تحياتي
أخوكم عمر
}}}
تم الشكر بواسطة:
#3
الكود التالي يوضح شكل الكود الموجود بالمثال الثالث وذلك بعد تحويل جزء من الكود الي دوال Functions و روتينات Method/Sub

وستلاحظ عزيز القارئ ان الكود الموجود في الحدث Paint قد اصبح أقل بكثير عن سابقة في المثال الثالث وهنا تظهر أهمية تحويل اجزاء من الكود الي دوال أو روتينان.


المثال الرابع:


كود :
Public Class Form1

Dim colorLightLight As Color = ControlPaint.Light(Color.SteelBlue)
Dim colorDarkDark As Color = (Color.Blue)
Dim colorDark As Color = (Color.MediumBlue)
Dim colorLight As Color = ControlPaint.Light(Color.Cyan)
Dim colorFrameOut As Color = ControlPaint.Dark(Color.Navy)
Dim colorFrameIn As Color = ControlPaint.Light(Color.LightSteelBlue)
Dim rect As New Rectangle(20, 20, 100, 25)
Dim rect1 As New Rectangle(20, 50, 100, 25)

Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
MyBase.OnPaint(e)

DrawGlow(e.Graphics, rect, colorLightLight, colorDarkDark, colorDark, colorLight, 5)
DrawGlow(e.Graphics, rect1, colorLightLight, colorDarkDark, colorDark, colorLight, colorFrameOut, colorFrameIn, 5)

End Sub

Private Function GetBorderPath(ByVal rect As Rectangle, ByVal displacement As Single) As GraphicsPath

rect.Width -= 1
rect.Height -= 1
Dim path As New GraphicsPath

path.AddLine((rect.Left + displacement), CSng(rect.Top), (rect.Right - displacement), CSng(rect.Top))
path.AddLine((rect.Right - displacement), CSng(rect.Top), CSng(rect.Right), (rect.Top + displacement))
path.AddLine(CSng(rect.Right), (rect.Top + displacement), CSng(rect.Right), (rect.Bottom - displacement))
path.AddLine(CSng(rect.Right), (rect.Bottom - displacement), (rect.Right - displacement), CSng(rect.Bottom))
path.AddLine((rect.Right - displacement), CSng(rect.Bottom), (rect.Left + displacement), CSng(rect.Bottom))
path.AddLine((rect.Left + displacement), CSng(rect.Bottom), CSng(rect.Left), (rect.Bottom - displacement))
path.AddLine(CSng(rect.Left), (rect.Bottom - displacement), CSng(rect.Left), (rect.Top + displacement))
path.AddLine(CSng(rect.Left), (rect.Top + displacement), (rect.Left + displacement), CSng(rect.Top))
Return path

End Function

Private Function GetBorderPath(ByVal rect As Rectangle, ByVal exclude As Rectangle, ByVal displacement As Single) As GraphicsPath

If exclude.IsEmpty Then
Return GetBorderPath(rect, displacement)
End If

rect.Width -= 1
rect.Height -= 1

Dim list As New List(Of PointF)

Dim x As Single = rect.X
Dim y As Single = rect.Y
Dim right As Single = rect.Right
Dim bottom As Single = rect.Bottom

Dim pt1 As Single = (rect.X + displacement)
Dim pt2 As Single = (rect.Right - displacement)
Dim pt3 As Single = (rect.Y + displacement)
Dim pt4 As Single = (rect.Bottom - displacement)
Dim pt5 As Single = IIf((displacement = 0.0F), 1.0F, displacement)

If ((rect.Y >= exclude.Top) AndAlso (rect.Y <= exclude.Bottom)) Then

Dim pt6 As Single = ((exclude.X - 1) - displacement)
Dim pt7 As Single = (exclude.Right + displacement)

If (pt1 <= pt6) Then
list.Add(New PointF(pt1, y))
list.Add(New PointF(pt6, y))
list.Add(New PointF((pt6 + displacement), (y - pt5)))
Else
pt6 = (exclude.X - 1)
list.Add(New PointF(pt6, y))
list.Add(New PointF(pt6, (y - pt5)))
End If

If (pt2 > pt7) Then
list.Add(New PointF((pt7 - displacement), (y - pt5)))
list.Add(New PointF(pt7, y))
list.Add(New PointF(pt2, y))
Else
pt7 = exclude.Right
list.Add(New PointF(pt7, (y - pt5)))
list.Add(New PointF(pt7, y))
End If

Else
list.Add(New PointF(pt1, y))
list.Add(New PointF(pt2, y))
End If

list.Add(New PointF(right, pt3))
list.Add(New PointF(right, pt4))
list.Add(New PointF(pt2, bottom))
list.Add(New PointF(pt1, bottom))
list.Add(New PointF(x, pt4))
list.Add(New PointF(x, pt3))

Dim path As New GraphicsPath

For i As Integer = 1 To list.Count - 1
path.AddLine(list.Item((i - 1)), list.Item(i))
Next

path.AddLine(list.Item((list.Count - 1)), list.Item(0))
Return path

End Function

Private Function GetBorderPath(ByVal rect As Rectangle) As GraphicsPath
Return GetBorderPath(rect, 0)
End Function

Private Function GetBorderPath(ByVal rect As Rectangle, ByVal radius As Integer) As GraphicsPath
Dim path As New GraphicsPath
If (radius = 0) Then
path.AddRectangle(rect)
Return path
End If
Return GetRoundedPath(rect, radius)
End Function

Private Function GetRoundedPath(ByVal rect As Rectangle, ByVal radius As Integer) As GraphicsPath
Return GetRoundedPath(rect, radius, radius, radius, radius)
End Function

Private Function GetRoundedPath(ByVal rect As Rectangle, _
ByVal TopLeftRaduis As Integer, _
ByVal TopRightRaduis As Integer, _
ByVal BottomLeftRadius As Integer, _
ByVal BottomRightRadius As Integer) As GraphicsPath

If ((TopLeftRaduis = 0) OrElse (TopLeftRaduis < 0)) Then
TopLeftRaduis = 1
End If

If ((TopRightRaduis = 0) OrElse (TopRightRaduis < 0)) Then
TopRightRaduis = 1
End If

If ((BottomLeftRadius = 0) OrElse (BottomLeftRadius < 0)) Then
BottomLeftRadius = 1
End If

If ((BottomRightRadius = 0) OrElse (BottomRightRadius < 0)) Then
BottomRightRadius = 1
End If

Dim x As Integer = rect.X
Dim y As Integer = rect.Y
Dim width As Integer = rect.Width
Dim height As Integer = rect.Height
Dim path As New GraphicsPath

path.AddArc(x, y, TopLeftRaduis, TopLeftRaduis, 180.0F, 90.0F)

If (TopRightRaduis <> 1) Then
path.AddArc(((x + width) - TopRightRaduis), y, TopRightRaduis, TopRightRaduis, 270.0F, 90.0F)
Else
path.AddLine((x + width), y, (x + width), width)
End If

If (BottomRightRadius <> 1) Then
path.AddArc(((x + width) - BottomRightRadius), ((y + height) - BottomRightRadius), BottomRightRadius, BottomRightRadius, 0.0F, 90.0F)
Else
path.AddLine(CInt((x + width)), CInt((y + height)), CInt((x + width)), CInt((y + height)))
End If

path.AddArc(x, ((y + height) - BottomLeftRadius), BottomLeftRadius, BottomLeftRadius, 90.0F, 90.0F)
path.CloseFigure()

Return path

End Function

Private Sub DrawBorder(ByVal g As Graphics, _
ByVal rect As Rectangle, _
ByVal borderColor As Color, _
ByVal TopLeftRaduis As Integer, _
ByVal TopRightRaduis As Integer, _
ByVal BottomLeftRadius As Integer, _
ByVal BottomRightRadius As Integer)

Using borderPen As Pen = New Pen(borderColor)
Using path As GraphicsPath = GetRoundedPath(rect, TopLeftRaduis, TopRightRaduis, BottomLeftRadius, BottomRightRadius)
g.DrawPath(borderPen, path)
End Using
End Using
End Sub

Private Sub DrawBorder(ByVal g As Graphics, ByVal rect As Rectangle, ByVal borderColor As Color)
DrawBorder(g, rect, borderColor, 0)
End Sub

Private Sub DrawBorder(ByVal g As Graphics, ByVal rect As Rectangle, ByVal borderColor As Color, ByVal radius As Integer)

Using borderPen As Pen = New Pen(borderColor)
Using path As GraphicsPath = GetBorderPath(rect, radius)
g.DrawPath(borderPen, path)
End Using
End Using

End Sub

Private Sub DrawGlow(ByVal g As Graphics, _
ByVal rect As Rectangle, _
ByVal colorLightLight As Color, _
ByVal colorDarkDark As Color, _
ByVal colorDark As Color, _
ByVal colorLight As Color, _
ByVal colorFrameOut As Color, _
ByVal colorFrameIn As Color, _
ByVal radius As Integer)

Dim mode As SmoothingMode = g.SmoothingMode
g.SmoothingMode = SmoothingMode.AntiAlias

Dim r As New Rectangle(rect.X, rect.Y, rect.Width, (rect.Height / 2))

Using lgb As LinearGradientBrush = New LinearGradientBrush(r, colorLightLight, colorDarkDark, 90.0F, True)

Using lgb1 As LinearGradientBrush = New LinearGradientBrush(r, colorDark, colorLight, -90.0F, True)

lgb1.WrapMode = WrapMode.TileFlipXY
lgb.WrapMode = WrapMode.TileFlipXY

Dim r1 As New Rectangle(rect.X, rect.Y, rect.Width, ((rect.Height / 2) + 1))
g.FillPath(lgb, GetRoundedPath(r1, radius, radius, 0, 0))

Dim path As New GraphicsPath

Dim r2 As New Rectangle((rect.X - 10), (rect.Y + (rect.Height / 2)), (rect.Width + 20), rect.Height)
Dim r3 As New Rectangle(rect.X, (rect.Y + (rect.Height / 2)), rect.Width, ((rect.Height / 2) + 1))

path.AddRectangle(r2)

Dim pgb As New PathGradientBrush(path)
pgb.SurroundColors = New Color() {colorDark, colorDark, ControlPaint.Light(colorLight), ControlPaint.Light(colorLight)}
pgb.CenterColor = ControlPaint.Light(colorLight)
g.FillPath(pgb, GetRoundedPath(r3, 0, 0, radius, radius))
path.Dispose()
End Using
End Using

Dim r4 As New Rectangle((rect.X + 1), (rect.Y + 1), (rect.Width - 2), (rect.Height - 2))

DrawBorder(g, r4, colorFrameIn, radius)
DrawBorder(g, rect, colorFrameOut, radius)

g.SmoothingMode = mode

End Sub

Private Sub DrawGlow(ByVal g As Graphics, _
ByVal rect As Rectangle, _
ByVal colorLightLight As Color, _
ByVal colorDarkDark As Color, _
ByVal colorDark As Color, _
ByVal colorLight As Color, _
ByVal radius As Integer)

Dim mode As SmoothingMode = g.SmoothingMode
g.SmoothingMode = SmoothingMode.AntiAlias
Dim r As New Rectangle(rect.X, rect.Y, rect.Width, (rect.Height / 2))
Using lgb As LinearGradientBrush = New LinearGradientBrush(r, colorLightLight, colorDarkDark, 90.0F, True)

Using lgb1 As LinearGradientBrush = New LinearGradientBrush(r, colorDark, colorLight, -90.0F, True)

lgb1.WrapMode = WrapMode.TileFlipXY
lgb.WrapMode = WrapMode.TileFlipXY

Dim r1 As New Rectangle(rect.X, rect.Y, rect.Width, ((rect.Height / 2) + 1))
g.FillPath(lgb, GetRoundedPath(r1, radius, radius, 0, 0))

Dim path As New GraphicsPath

Dim r2 As New Rectangle((rect.X - 10), (rect.Y + (rect.Height / 2)), (rect.Width + 20), rect.Height)
Dim r3 As New Rectangle(rect.X, (rect.Y + (rect.Height / 2)), rect.Width, ((rect.Height / 2) + 1))

path.AddRectangle(r2)

Dim pgb As New PathGradientBrush(path)
pgb.SurroundColors = New Color() {colorDark, colorDark, ControlPaint.Light(colorLight), ControlPaint.Light(colorLight)}
pgb.CenterColor = ControlPaint.Light(colorLight)
g.FillPath(pgb, GetRoundedPath(r3, 0, 0, radius, radius))
path.Dispose()
End Using
End Using


g.SmoothingMode = mode

End Sub

End Class

في المشاركة التالية سنعطي مثالا لكيفية استخدام الأفكار السابقة في بناء شئ مفيد


تقبلوا تحياتي
أخوكم عمر
}}}
تم الشكر بواسطة:
#4
التطبيق :

في الكود الموجود بالمرفقات ستجدون فكرة عن كيفية استخدام الأفكار أعلاه في بناء باتون يختلف كثيرا عن الباتون العادي والموجود في الدوت نت وهو يختلف عن المثال الموجود في الجزء الثاني من سلسة المقالات الخاصة بالجرافكس حيث في الجزء الثاني كان الباتون دائريا أما في هذا المثال سيكون الباتون علي شكل مستطيل له حواف دائرية إضافة الي ذلك ستجدون فكرة مبسطة عن كيفية الاستفادة من نفس الأفكار أعلاه في بناء Panel بسيط ولكن بشكل مختلف

أتمني أن يكون الموضوع مفيدا لكم بشكل ما

بالمرفقات ستجدون نسخة من الكود بنسخة الفيجوال 2010 و أيضا بنسخة الفيجوال 2008

تقبلو تحياتي
أخوكم عمر


الملفات المرفقة
.rar   GaphicsIdeas_Part3_VS2008.rar (الحجم : 122.43 ك ب / التحميلات : 63)
.rar   GaphicsIdeas_Part3_VS2010.rar (الحجم : 83.85 ك ب / التحميلات : 57)
}}}
تم الشكر بواسطة:


المواضيع المحتمل أن تكون متشابهة .
الموضوع : الكاتب الردود : المشاهدات : آخر رد
  الجزء الثالث من:كيف تجعل الـ Text Box ذكي!يترجم العمليات الحسابية ويخرج الناتج (الأقواس المتعددة) !! أنس محمود 10 7,840 19-07-22, 12:15 AM
آخر رد: StartLight4000
  مقال: الكومبو بوكس ComboBox كيف تضيف أيقونات Blue Sky 1 3,162 30-06-19, 10:41 AM
آخر رد: invocker
  حساب قيمة معادلة(اقصد صيغة دون مجاهيل) مكتوبة بالتكست : الجزء الخامس والاخير محمد شريقي 4 4,521 23-02-18, 10:44 PM
آخر رد: العواد الصغير
  أفكار في الجرافكس AlignRectangle silverlight 0 1,558 14-10-17, 02:02 PM
آخر رد: silverlight
  مقدمة إلي إخفاء المعلومات - الجزء الأول silverlight 5 4,156 07-01-17, 10:44 PM
آخر رد: Basil Abdallah
  مقدمة إلي إخفاء المعلومات - الجزء الثاني silverlight 1 3,027 06-01-17, 11:52 AM
آخر رد: silverlight
  تحويل الفيديو في برامجك-الجزء الثاني( إصلاح للمشاكل + تعديل للروابط + توضيح للأمر ) RaggiTech 1 3,282 10-12-14, 06:37 PM
آخر رد: abulayth
  الجزء الثاني من:كيف تجعل الـ Text Box ذكي!يترجم العمليات الحسابية ويخرج الناتج ( العمليات المتعددة)! أنس محمود 0 2,820 22-02-13, 12:39 AM
آخر رد: أنس محمود
  مقال- كيفية الاستغناء عن الداتا بيز التقليدية في برامجنا – ألجزء الأول RaggiTech 1 3,428 06-10-12, 12:23 AM
آخر رد: RaggiTech
  مقال- تطوير الكونترول Property Attributes الجزء الثالث RaggiTech 0 2,271 06-10-12, 12:20 AM
آخر رد: RaggiTech

التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم