تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
كود- تكست بوكس شفاف Transparent TextBox
#1
كاتب الموضوع : silverlight

أضف الكلاس التالي الي مشروعك ثم عليك عمل Build للكلاس ومن ثم استخدامه بعد ذلك داخل الفورم


كود :
Public Class cTextBox

Inherits TextBox

Private m_opacity As Double
Private m_backcolor As Color = Color.Transparent
Private m_fillColor As Color = Color.Chocolate

#Region " Constructor "

Public Sub New()

SetStyle(ControlStyles.SupportsTransparentBackColor, True)
SetStyle(ControlStyles.Opaque, False)
SetStyle(ControlStyles.DoubleBuffer, True)
SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
SetStyle(ControlStyles.AllPaintingInWmPaint, True)
SetStyle(ControlStyles.UserPaint, True)
UpdateStyles()
m_opacity = 1.0R

End Sub

#End Region

#Region " Property "

<System.ComponentModel.DefaultValue(1.0R)> _
<System.ComponentModel.TypeConverter(GetType(OpacityConverter))> _
<System.ComponentModel.Description("Set the opacity percentage of the control.")> _
<System.ComponentModel.Category("Control Style")> _
Public Property Opacity() As Double
Get
Return m_opacity
End Get
Set(ByVal value As Double)
m_opacity = value
UpdateStyles()
Refresh()
End Set
End Property

<System.ComponentModel.Browsable(False)> _
<System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)> _
<System.ComponentModel.DefaultValue(GetType(Color), "Transparent")> _
<System.ComponentModel.Description("Set background color.")> _
<System.ComponentModel.Category("Control Style")> _
Public Overrides Property BackColor() As System.Drawing.Color
Get
Return m_backcolor
End Get
Set(ByVal value As System.Drawing.Color)
m_backcolor = value
Invalidate()
End Set
End Property

<System.ComponentModel.DefaultValue(GetType(Color), "Chocolate")> _
<System.ComponentModel.Description("Set hot color.")> _
<System.ComponentModel.Category("Control Style")> _
Public Property FillColor() As Color
Get
Return m_fillColor
End Get
Set(ByVal value As Color)
m_fillColor = value
Invalidate()
End Set
End Property


#End Region

#Region " Event "

Protected Overrides Sub OnResize(ByVal e As System.EventArgs)
MyBase.OnResize(e)
Invalidate()

End Sub

Protected Overrides Sub OnKeyDown(ByVal e As System.Windows.Forms.KeyEventArgs)
MyBase.OnKeyDown(e)
Invalidate()

End Sub

Protected Overrides Sub OnKeyUp(ByVal e As System.Windows.Forms.KeyEventArgs)
MyBase.OnKeyUp(e)
Invalidate()

End Sub

Protected Overrides Sub OnKeyPress(ByVal e As System.Windows.Forms.KeyPressEventArgs)
MyBase.OnKeyPress(e)
Invalidate()

End Sub

Protected Overrides Sub OnMouseUp(ByVal mevent As System.Windows.Forms.MouseEventArgs)
MyBase.OnMouseUp(mevent)
Invalidate()

End Sub

Protected Overrides Sub OnMouseLeave(ByVal e As System.EventArgs)

Dim ptCursor As Point = Cursor.Position
Dim f As Form = Me.FindForm()
ptCursor = f.PointToClient(ptCursor)
If Not Me.Bounds.Contains(ptCursor) Then
MyBase.OnMouseLeave(e)
End If

End Sub

Protected Overrides Sub OnGiveFeedback(ByVal gfbevent As System.Windows.Forms.GiveFeedbackEventArgs)
MyBase.OnGiveFeedback(gfbevent)
Invalidate()

End Sub

Protected Overrides Sub OnChangeUICues(ByVal e As System.Windows.Forms.UICuesEventArgs)
MyBase.OnChangeUICues(e)
Invalidate()

End Sub

Protected Overrides Sub OnGotFocus(ByVal e As System.EventArgs)
MyBase.OnGotFocus(e)
Invalidate()

End Sub

Protected Overrides Sub OnLostFocus(ByVal e As System.EventArgs)
MyBase.OnLostFocus(e)
Invalidate()

End Sub

Protected Overrides Sub OnTextChanged(ByVal e As System.EventArgs)
MyBase.OnTextChanged(e)
Invalidate()

End Sub

Protected Overrides Sub OnFontChanged(ByVal e As System.EventArgs)
MyBase.OnFontChanged(e)

Invalidate()

End Sub

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

Using sb As New SolidBrush(Me.BackColor)

e.Graphics.FillRectangle(sb, Me.ClientRectangle)
sb.Dispose()

Using fsb As New SolidBrush(Color.FromArgb(Me.Opacity * 255, Me.FillColor))

e.Graphics.FillRectangle(fsb, Me.ClientRectangle)
fsb.Dispose()

End Using

If Me.Text IsNot Nothing Then

e.Graphics.DrawString(Me.Text, Me.Font, New SolidBrush(Me.ForeColor), 0, 0)

End If

End Using
End Sub

#End Region

End Class
مع تحياتي
أخوكم عمر
}}}
تم الشكر بواسطة: العواد الصغير , العواد الصغير



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


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