تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
مقال- Custom EventHandler & Classes - الجزء الأول
#5
الكود التالي يوضح بعض الكلاسات الإضافية التي قمت بكتابتها وهي كالأتي

ThemeConverter Class
ThemeEditor Class
ThemesUtilty Clss


كود :
Imports System.ComponentModel.Design.Serialization
Imports System.ComponentModel
Imports System.Globalization
Imports System.Reflection
Imports System.Drawing

Public Class ThemeConverter
Inherits ExpandableObjectConverter

#Region " Constructor "
Public Sub New()
End Sub
#End Region

#Region " Methods "

Public Overrides Function CanConvertFrom(ByVal context As ITypeDescriptorContext, _
ByVal sourceType As Type) As Boolean
Return ((sourceType Is GetType(InstanceDescriptor)) OrElse MyBase.CanConvertFrom(context, sourceType))
End Function

Public Overrides Function CanConvertTo(ByVal context As ITypeDescriptorContext, _
ByVal destinationType As Type) As Boolean

Return ((destinationType Is GetType(String)) OrElse ((destinationType Is GetType(InstanceDescriptor)) OrElse MyBase.CanConvertTo(context, destinationType)))
End Function

Public Overrides Function GetProperties(ByVal context As ITypeDescriptorContext, _
ByVal value As Object, _
ByVal attributes As Attribute()) As PropertyDescriptorCollection

Return TypeDescriptor.GetProperties(value, attributes).Sort(New String() {"ThemeNorthBegin", _
"ThemeNorthEnd", _
"ThemeSouthBegin", _
"ThemeSouthEnd", _
"ThemeBorderOut", _
"ThemeBorderIn"})
End Function

Public Overrides Function ConvertTo(ByVal context As ITypeDescriptorContext, _
ByVal culture As CultureInfo, _
ByVal value As Object, _
ByVal destinationType As Type) As Object

If (destinationType Is GetType(InstanceDescriptor)) Then

Dim t As Type = value.GetType
Dim ThemeColor As PropertyDescriptorCollection = TypeDescriptor.GetProperties(value)

Dim m_ThemeNorthBegin As Color = DirectCast(ThemeColor.Item("ThemeNorthBegin").GetValue(value), Color)
Dim m_ThemeNorthEnd As Color = DirectCast(ThemeColor.Item("ThemeNorthEnd").GetValue(value), Color)
Dim m_ThemeSouthBegin As Color = DirectCast(ThemeColor.Item("ThemeSouthBegin").GetValue(value), Color)
Dim m_ThemeSouthEnd As Color = DirectCast(ThemeColor.Item("ThemeSouthEnd").GetValue(value), Color)
Dim m_ThemeBorderOut As Color = DirectCast(ThemeColor.Item("ThemeBorderOut").GetValue(value), Color)
Dim m_ThemeBorderIn As Color = DirectCast(ThemeColor.Item("ThemeBorderIn").GetValue(value), Color)


Dim constructor As ConstructorInfo = t.GetConstructor(New Type() {GetType(Color), _
GetType(Color), _
GetType(Color), _
GetType(Color), _
GetType(Color), _
GetType(Color)})

If (constructor IsNot Nothing) Then
Return New InstanceDescriptor(constructor, New Object() {m_ThemeNorthBegin, _
m_ThemeNorthEnd, _
m_ThemeSouthBegin, _
m_ThemeSouthEnd, _
m_ThemeBorderOut, _
m_ThemeBorderIn}, True)
End If

End If

Return MyBase.ConvertTo(context, culture, value, destinationType)
End Function

#End Region

End Class ' ThemeConverter Class


كود :
Imports System.Drawing.Design
Public Class ThemeEditor
Inherits UITypeEditor

#Region " Constructor "
Public Sub New()
End Sub
#End Region

#Region " Methods "
Public Overrides Function GetEditStyle(ByVal context As System.ComponentModel.ITypeDescriptorContext) As System.Drawing.Design.UITypeEditorEditStyle
Return UITypeEditorEditStyle.None
End Function

Public Overrides Function GetPaintValueSupported(ByVal context As System.ComponentModel.ITypeDescriptorContext) As Boolean
Return True
End Function
#End Region

End Class ' ThemeEditor Class


كود :
Imports System.Drawing.Drawing2D

Friend NotInheritable Class ThemesUtility

#Region " Methods "

Public Shared Sub DrawGradientRectangle(ByVal g As Graphics, ByVal rect As Rectangle, _
ByVal colorUpBegin As Color, _
ByVal colorUpEnd As Color, _
ByVal colorDownBegin As Color, _
ByVal colorDownEnd As Color, _
ByVal colorBorderOut As Color, _
ByVal colorBorderIn As Color)

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

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


Dim topBlend As New Blend
Dim topBlendFactors As Single() = {0.0F, 0.2F, 0.5F, 0.7F, 1.0F, 0.7F, 0.5F, 0.2F, 0.0F}
Dim topBlendPositions As Single() = {0.0F, 0.1F, 0.3F, 0.4F, 0.5F, 0.6F, 0.7F, 0.8F, 1.0F}
topBlend.Factors = topBlendFactors
topBlend.Positions = topBlendPositions

Dim bottomBlend As New Blend
Dim bottomBlendFactors As Single() = {0.0F, 0.2F, 0.5F, 0.7F, 1.0F, 0.7F, 0.5F, 0.2F, 0.0F}
Dim bottomBlendPositions As Single() = {0.0F, 0.1F, 0.3F, 0.4F, 0.5F, 0.6F, 0.7F, 0.8F, 1.0F}
bottomBlend.Factors = bottomBlendFactors
bottomBlend.Positions = bottomBlendPositions

Using lgbBottom As LinearGradientBrush = New LinearGradientBrush(rect, colorDownBegin, colorDownEnd, 90.0F, True)
lgbBottom.Blend = bottomBlend
g.FillRectangle(lgbBottom, rect)
End Using

Using lgbTop As LinearGradientBrush = New LinearGradientBrush(r, colorUpBegin, colorUpEnd, 200, True)
lgbTop.Blend = topBlend
g.FillRectangle(lgbTop, r)
End Using

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

Using innerBorderPen As New Pen(colorBorderIn)
g.DrawRectangle(innerBorderPen, InnerBorderRectanggle)
End Using

Using OuterBorderPen As New Pen(colorBorderOut)
g.DrawRectangle(OuterBorderPen, InnerBorderRectanggle)
End Using

g.SmoothingMode = mode

End Sub

Public Shared Function DrawGradient(ByVal g As Graphics, ByVal rect As Rectangle, _
ByVal colorUpBegin As Color, _
ByVal colorUpEnd As Color, _
ByVal colorDownBegin As Color, _
ByVal colorDownEnd As Color, _
ByVal colorBorderOut As Color, _
ByVal colorBorderIn As Color) As Boolean

DrawGradientRectangle(g, rect, colorUpBegin, colorUpEnd, colorDownBegin, colorDownEnd, colorBorderOut, colorBorderIn)
Return True
End Function

#End Region

End Class

وفي المشاركة التالية سوف نوضح كيف نستفيد من الكلاس ThemeColors وكيف نضيفه الي كونترول ومن ثم نستخدمه في رسم شئ ما علي الكونترول

يتبع في المشاركة التالية ...............................................
}}}
تم الشكر بواسطة:


الردود في هذا الموضوع
مقال- Custom EventHandler & Classes - الجزء الأول - بواسطة Raggi Tech - 05-10-12, 11:47 AM

المواضيع المحتمل أن تكون متشابهة .
الموضوع : الكاتب الردود : المشاهدات : آخر رد
  الجزء الثالث من:كيف تجعل الـ Text Box ذكي!يترجم العمليات الحسابية ويخرج الناتج (الأقواس المتعددة) !! أنس محمود 10 8,373 19-07-22, 12:15 AM
آخر رد: StartLight4000
  مقال: الكومبو بوكس ComboBox كيف تضيف أيقونات Blue Sky 1 3,448 30-06-19, 10:41 AM
آخر رد: invocker
  [درس فيديو] مثال بسيط لبرنامج إجازات فقط لأغراض الشرح (الدرس الأول) عبدالله الدوسري 7 12,084 28-04-18, 06:55 PM
آخر رد: moniam
  الفرق بين الأصناف Classes و الكائنات Objects RaggiTech 1 8,440 28-03-18, 10:30 PM
آخر رد: alsouf
  حساب قيمة معادلة(اقصد صيغة دون مجاهيل) مكتوبة بالتكست : الجزء الخامس والاخير محمد شريقي 4 4,826 23-02-18, 10:44 PM
آخر رد: العواد الصغير
  مقدمة إلي إخفاء المعلومات - الجزء الأول silverlight 5 4,501 07-01-17, 10:44 PM
آخر رد: Basil Abdallah
  مقدمة إلي إخفاء المعلومات - الجزء الثاني silverlight 1 3,209 06-01-17, 11:52 AM
آخر رد: silverlight
  تحويل الفيديو في برامجك-الجزء الثاني( إصلاح للمشاكل + تعديل للروابط + توضيح للأمر ) RaggiTech 1 3,506 10-12-14, 06:37 PM
آخر رد: abulayth
  الجزء الثاني من:كيف تجعل الـ Text Box ذكي!يترجم العمليات الحسابية ويخرج الناتج ( العمليات المتعددة)! أنس محمود 0 3,002 22-02-13, 12:39 AM
آخر رد: أنس محمود
  مقال- كيفية الاستغناء عن الداتا بيز التقليدية في برامجنا – ألجزء الأول RaggiTech 1 3,683 06-10-12, 12:23 AM
آخر رد: RaggiTech

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


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