01-06-18, 03:02 AM
(آخر تعديل لهذه المشاركة : 01-06-18, 03:02 AM {2} بواسطة silverlight.)
الشفافية لكي تتحقق تماما يجب التعامل مع الألوان و الصور في نفس الوقت
خاصة ان جميع الكونترول تحصل علي شفافيتها من الفورم نفسه
الكود التالي عبارة عن مثال بسيط يوضح كيفية الحصول غلي label شفاف بالتعامل مع الألوان فقط
خاصة ان جميع الكونترول تحصل علي شفافيتها من الفورم نفسه
الكود التالي عبارة عن مثال بسيط يوضح كيفية الحصول غلي label شفاف بالتعامل مع الألوان فقط
PHP كود :
Imports System.ComponentModel
Public Class CairoLabel
Inherits Label
Private _opacity As Double = 1
Public Sub New()
MyBase.SetStyle(ControlStyles.UserPaint, True)
MyBase.SetStyle(ControlStyles.ResizeRedraw, True)
MyBase.SetStyle(ControlStyles.SupportsTransparentBackColor, True)
MyBase.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
MyBase.SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
End Sub
<Browsable(True), EditorBrowsable(EditorBrowsableState.Always), DefaultValue(1.0R), TypeConverter(GetType(OpacityConverter))>
<RefreshProperties(RefreshProperties.All), Description("Gets or set the opacity percentage of the control."), Category("Cairo")>
Public Overridable Property Opacity() As Double
Get
Return _opacity
End Get
Set(value As Double)
_opacity = value
Dim c As Color = Me.BackColor
Dim alpha As Byte = CalcualteOpacity(value)
Me.BackColor = UpdateControlColor(c, alpha)
Me.Invalidate()
End Set
End Property
Protected Overrides Sub OnBackColorChanged(e As EventArgs)
MyBase.OnBackColorChanged(e)
Dim c As Color = Me.BackColor
Dim alpha As Byte = CalcualteOpacity(_opacity)
Me.BackColor = UpdateControlColor(c, alpha)
Me.Invalidate()
End Sub
Private Function UpdateControlColor(source As Color, alpha As Byte) As Color
alpha = Byte.MaxValue - alpha
Return Color.FromArgb(CInt((1 - (alpha / Byte.MaxValue)) * Byte.MaxValue), source)
End Function
Private Function CalcualteOpacity(value As Double) As Byte
Return CByte((If(value > 1, 1, If(value < 0, 0, value))) * 255)
End Function
End Class
Retired

