LABEL ET IMAGE DANS TEXTBOX

BadoqueAlex Messages postés 129 Date d'inscription mardi 20 juillet 2004 Statut Membre Dernière intervention 6 juin 2009 - 22 juin 2009 à 14:20
cs_claudetom Messages postés 115 Date d'inscription jeudi 11 octobre 2001 Statut Membre Dernière intervention 15 octobre 2012 - 22 juin 2009 à 21:02
Cette discussion concerne un article du site. Pour la consulter dans son contexte d'origine, cliquez sur le lien ci-dessous.

https://codes-sources.commentcamarche.net/source/50212-label-et-image-dans-textbox

cs_claudetom Messages postés 115 Date d'inscription jeudi 11 octobre 2001 Statut Membre Dernière intervention 15 octobre 2012
22 juin 2009 à 21:02
suite réponse du créateur du code, je poste le mien:
implémentation : comme un objet Textbox

<Li>
' post original by Zijian
'http://www.codeproject.com/KB/miscctrl/Parasite_Pattern2.aspx
'revision par gillardg
'traduction en vb.net et ajout d'une propriété image

Imports System.Windows.Forms

Public Class TextBox
Inherits System.Windows.Forms.TextBox

Protected lab As Label

''' <summary>
''' Nouveau Textbox
''' </summary>
''' <remarks></remarks>
Public Sub New()
lab = New Label()
lab.Text = hint

lab.ForeColor = SystemColors.ActiveBorder
Me.Controls.Add(lab)
lab.Dock = DockStyle.Fill
AddHandler lab.Click, AddressOf panel_Click

If String.IsNullOrEmpty(Me.Text) Then
lab.Show()
End If
End Sub

''' <summary>
''' usage :
''' dans l'évenement Load de la form ( MyBase.Load )
''' Dim tex As New InTextboxLabel("User Name", Image.FromFile("annsom.png"))
''' </summary>
'''

'''

''' <remarks></remarks>
Public Sub New(ByVal hint As String, Optional ByVal picture As Image = Nothing)
Me.New()
Me.Hint = hint
Me.Picture = picture
End Sub

#Region " Propriétés "
Private m_HintAlignment As ContentAlignment = ContentAlignment.MiddleLeft
Public Property HintAlignment() As ContentAlignment
Get
Return m_HintAlignment
End Get
Set(ByVal value As ContentAlignment)
m_HintAlignment = value
lab.TextAlign = m_HintAlignment
End Set
End Property

Private m_Hint As String = "Entrer un texte"
Public Property Hint() As String
Get
Return m_Hint
End Get
Set(ByVal value As String)
m_Hint = value
lab.Text = Hint
End Set
End Property

Private m_PictureAlignment As ContentAlignment = ContentAlignment.MiddleRight
Public Property PictureAlignment() As ContentAlignment
Get
Return m_PictureAlignment
End Get
Set(ByVal value As ContentAlignment)
m_PictureAlignment = value
lab.ImageAlign = m_PictureAlignment
End Set
End Property

Private m_Picture As Image
Public Property Picture() As Image
Get
Return m_Picture
End Get
Set(ByVal value As Image)
m_Picture = value
If Not m_Picture Is Nothing Then
lab.Image = m_Picture
End If
End Set
End Property
#End Region

Protected Overrides Sub OnTextChanged(ByVal e As System.EventArgs)
MyBase.OnTextChanged(e)
If (Not String.IsNullOrEmpty(Me.Text)) Then
lab.Hide()
ElseIf (Not Me.Focused) Then
lab.Show()
End If
End Sub

Private Sub panel_Click(ByVal sender As Object, ByVal e As EventArgs)
lab.Hide()
Me.Select()
End Sub

Protected Overrides Sub OnLeave(ByVal e As System.EventArgs)
MyBase.OnLeave(e)
If String.IsNullOrEmpty(Me.Text) Then
lab.Show()
End If
End Sub

Protected Overrides Sub OnEnter(ByVal e As System.EventArgs)
MyBase.OnEnter(e)
lab.Hide()
End Sub
End Class </Li>
gillardg Messages postés 3275 Date d'inscription jeudi 3 avril 2008 Statut Membre Dernière intervention 14 septembre 2014 2
22 juin 2009 à 17:42
si tu as 25 textbox ??
BadoqueAlex Messages postés 129 Date d'inscription mardi 20 juillet 2004 Statut Membre Dernière intervention 6 juin 2009
22 juin 2009 à 14:20
Pas mal mais j'aurais plutôt ajouté une propriété au controle TextBox existant du genre TextIsEmpty.
Rejoignez-nous