Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Class OllydbgTxtBOX
- Inherits TextBox
- Private oldFont As Font = Nothing
- Private bTextoEnVacio As Boolean = False
- #Region "Nuevo Atributos"
- Private _TextoEnVacioColor As Color = Drawing.Color.Gray
- <System.ComponentModel.Description("Color del texto cuando el 'TextBox' está vacio")> _
- Public Property TextVacioColor() As Color
- Get
- Return _TextoEnVacioColor
- End Get
- Set(ByVal value As Color)
- _TextoEnVacioColor = value
- Me.Invalidate()
- End Set
- End Property
- Private _TextTextoVacio As String = "<Sin descripción>"
- <System.ComponentModel.Description("Texto o cuando el 'TextoBox' está vacio")> _
- Public Property TextVacio() As String
- Get
- Return _TextTextoVacio
- End Get
- Set(ByVal value As String)
- _TextTextoVacio = value
- Me.Invalidate()
- End Set
- End Property
- Private _TextEnCursiva As Boolean = False
- <System.ComponentModel.Description("El 'TextVacio' se escribirá en cursiva o no")> _
- Public Property TextVacioEnCursiva() As Boolean
- Get
- Return _TextEnCursiva
- End Get
- Set(ByVal value As Boolean)
- _TextEnCursiva = value
- Me.Invalidate()
- End Set
- End Property
- #End Region
- ' Default constructor
- Public Sub New()
- JoinEvents(True)
- End Sub
- ' Override OnCreateControl
- Protected Overrides Sub OnCreateControl()
- MyBase.OnCreateControl()
- TextoVacio_SeleccionEv(Nothing, Nothing)
- End Sub
- Private Sub JoinEvents(ByVal join As Boolean)
- If join Then
- AddHandler (TextChanged), AddressOf TextoVacio_SeleccionEv
- AddHandler (LostFocus), AddressOf TextoVacio_SeleccionEv
- AddHandler (FontChanged), AddressOf TextoVacio_FuenteEv
- 'Los eventos de arriba no se incian inmediatamente
- 'Los llamamos cuando el control esta creado
- 'Otra solucion alternativa: Usar un Timer para mirar las propiedades
- End If
- End Sub
- Private Sub TextoVacio_SeleccionEv(ByVal sender As Object, ByVal args As EventArgs)
- If Me.Text.Length <= 0 Then
- ActivarTextoVacio()
- Else
- DesactivarTextoVacio()
- End If
- End Sub
- Private Sub TextoVacio_FuenteEv(ByVal sender As Object, ByVal args As EventArgs)
- If bTextoEnVacio Then
- oldFont = New Font(Font.FontFamily, Font.Size, Font.Style, Font.Unit)
- Refresh()
- End If
- End Sub
- Private Sub ActivarTextoVacio()
- 'Fuente actual:
- oldFont = New Font(Font.FontFamily, Font.Size, Font.Style, Font.Unit)
- 'Activar el OnPaint:
- Me.SetStyle(ControlStyles.UserPaint, True)
- Me.bTextoEnVacio = True
- 'Pintar inmediatamente
- Refresh()
- End Sub
- Private Sub DesactivarTextoVacio()
- 'Desactivar el OnPaint
- Me.bTextoEnVacio = False
- Me.SetStyle(ControlStyles.UserPaint, False)
- If Not oldFont Is Nothing Then
- Me.Font = New Font(Font.FontFamily, Font.Size, Font.Style, Font.Unit)
- End If
- End Sub
- Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
- Dim drawFont As Font
- If bTextoEnVacio = True Then
- If _TextEnCursiva = False Then
- drawFont = New Font(Font.FontFamily, Font.Size, Font.Style, Font.Unit)
- Else
- drawFont = New Font(Font.FontFamily, Font.Size, FontStyle.Italic, Font.Unit)
- End If
- Else
- drawFont = New Font(Font.FontFamily, Font.Size, Font.Style, Font.Unit)
- End If
- Dim drawBrush As SolidBrush = New SolidBrush(Me.TextVacioColor)
- e.Graphics.DrawString(IIf(bTextoEnVacio, TextVacio, Text).ToString(), drawFont, drawBrush, New Point(0, 0))
- MyBase.OnPaint(e)
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement