05-10-12, 11:47 AM
الكود التالي يوضح بعض الكلاسات الإضافية التي قمت بكتابتها وهي كالأتي
ThemeConverter Class
ThemeEditor Class
ThemesUtilty Clss
وفي المشاركة التالية سوف نوضح كيف نستفيد من الكلاس ThemeColors وكيف نضيفه الي كونترول ومن ثم نستخدمه في رسم شئ ما علي الكونترول
يتبع في المشاركة التالية ...............................................
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 وكيف نضيفه الي كونترول ومن ثم نستخدمه في رسم شئ ما علي الكونترول
يتبع في المشاركة التالية ...............................................
