begin process at 2012 02 12 17:50:22
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Control

 > LABEL ET IMAGE DANS TEXTBOX

LABEL ET IMAGE DANS TEXTBOX


 Information sur la source

Note :
6 / 10 - par 1 personne
6,00 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10
Catégorie :Control Source .NET ( DotNet ) Classé sous :control, backgroundimage, textbox, backgroundtext Niveau :Débutant Date de création :22/06/2009 Vu :3 986

Auteur : gillardg

Ecrire un message privé
Site perso
Ce membre participe au partage de revenus publicitaires
Commentaire sur cette source (3)
Ajouter un commentaire et/ou une note


 Description

une petite classe qui améliore la TextBox
on ajoute un background label et une background picture
qui disparait quand la textbox a le focus
et qui réaparait seulement quand TextBox.Text=String.Empty

Source

  • ' 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
  • Public Class InTextboxLabel
  • Protected box As TextBoxBase
  • Protected hint As String
  • Protected lab As Label
  • ''' <summary>
  • ''' usage :
  • ''' dans l'évenement Load de la form ( MyBase.Load )
  • ''' Dim tex As New InTextboxLabel(tb1, "User Name", Image.FromFile("annsom.png"))
  • ''' </summary>
  • ''' <param name="box"></param>
  • ''' <param name="hint"></param>
  • ''' <param name="picture"></param>
  • ''' <remarks></remarks>
  • Public Sub New(ByVal box As TextBoxBase, ByVal hint As String, Optional ByVal picture As Image = Nothing)
  • Me.box = box
  • Me.hint = hint
  • AddHandler box.Enter, AddressOf box_Enter
  • AddHandler box.Leave, AddressOf box_Leave
  • AddHandler box.TextChanged, AddressOf box_TextChanged
  • lab = New Label()
  • lab.Text = hint
  • lab.Image = picture
  • lab.ForeColor = SystemColors.ActiveBorder
  • box.Controls.Add(lab)
  • lab.Dock = DockStyle.Fill
  • AddHandler lab.Click, AddressOf panel_Click
  • If String.IsNullOrEmpty(box.Text) Then
  • lab.Show()
  • End If
  • End Sub
  • Private Sub box_TextChanged(ByVal sender As Object, ByVal e As EventArgs)
  • If (Not String.IsNullOrEmpty(box.Text)) Then
  • lab.Hide()
  • ElseIf (Not box.Focused) Then
  • lab.Show()
  • End If
  • End Sub
  • Private Sub panel_Click(ByVal sender As Object, ByVal e As EventArgs)
  • lab.Hide()
  • box.Select()
  • End Sub
  • Private Sub box_Leave(ByVal sender As Object, ByVal e As EventArgs)
  • If String.IsNullOrEmpty(box.Text) Then
  • lab.Show()
  • End If
  • End Sub
  • Private Sub box_Enter(ByVal sender As Object, ByVal e As EventArgs)
  • lab.Hide()
  • End Sub
  • End Class
' 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
Public Class InTextboxLabel

    Protected box As TextBoxBase
    Protected hint As String
    Protected lab As Label
    ''' <summary>
    ''' usage :
    ''' dans l'évenement Load de la form ( MyBase.Load )
    ''' Dim tex As New InTextboxLabel(tb1, "User Name", Image.FromFile("annsom.png"))
    ''' </summary>
    ''' <param name="box"></param>
    ''' <param name="hint"></param>
    ''' <param name="picture"></param>
    ''' <remarks></remarks>
    Public Sub New(ByVal box As TextBoxBase, ByVal hint As String, Optional ByVal picture As Image = Nothing)
        Me.box = box
        Me.hint = hint

        AddHandler box.Enter, AddressOf box_Enter
        AddHandler box.Leave, AddressOf box_Leave
        AddHandler box.TextChanged, AddressOf box_TextChanged

        lab = New Label()
        lab.Text = hint

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

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

    Private Sub box_TextChanged(ByVal sender As Object, ByVal e As EventArgs)
        If (Not String.IsNullOrEmpty(box.Text)) Then
            lab.Hide()
        ElseIf (Not box.Focused) Then
            lab.Show()
        End If
    End Sub

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

    Private Sub box_Leave(ByVal sender As Object, ByVal e As EventArgs)
        If String.IsNullOrEmpty(box.Text) Then
            lab.Show()
        End If
    End Sub

    Private Sub box_Enter(ByVal sender As Object, ByVal e As EventArgs)
        lab.Hide()
    End Sub
End Class

 Conclusion

ça fait longtemps que j'avais pas posté

question souvent posée, voila une réponse


 Sources du même auteur

Source avec Zip Source avec une capture Source .NET (Dotnet) EDITEUR DE TEXTE WINFORM AVEC CORRECTEUR ORTHOGRAPHIQUE WPF
Source avec Zip Source avec une capture Source .NET (Dotnet) VBZIP GESTION D'ARCHIVES AU FORMAT ZIP UTILISANT IONIC.UTIL...
Source avec Zip Source avec une capture Source .NET (Dotnet) VBZIP ZIP ET UNZIP EN VB.NET
Source avec Zip Source .NET (Dotnet) API WIN32 FACILE
Source avec Zip Source .NET (Dotnet) BACKUP SIMPLE EN 100 LIGNES

 Sources de la même categorie

Source avec Zip COMMUNICATION MODBUS MASTER par sergelapointe
Source avec Zip Source avec une capture DÉPLACEMENT AVEC FLÈCHES DANS UN PAVÉ DE TEXTBOX 9X9 DYNAMIQ... par EhJoe
Source avec Zip Source avec une capture Source .NET (Dotnet) CONTROLSTARS EN RÉPONSE À JAKNIGHT007 par bigboss9
Source avec Zip Source avec une capture Source .NET (Dotnet) CALENDRIER ANNUEL NORME ISO par Prog1001
Source avec Zip Source avec une capture Source .NET (Dotnet) CONTROLE STARS par jaknight007

 Sources en rapport avec celle ci

Source avec Zip TEXTBOX EN NUMÉRIQUE par 320C
Source avec Zip Source avec une capture DÉPLACEMENT AVEC FLÈCHES DANS UN PAVÉ DE TEXTBOX 9X9 DYNAMIQ... par EhJoe
Source avec Zip PARAMETRES SETTINGS VBA par Le Pivert
Source avec Zip Source avec une capture Source .NET (Dotnet) CONTROLSTARS EN RÉPONSE À JAKNIGHT007 par bigboss9
Source avec Zip Source .NET (Dotnet) 4 CONTRÔLES PRATIQUES par Mononcle0

Commentaires et avis

Commentaire de BadoqueAlex le 22/06/2009 14:20:00 6/10

Pas mal mais j'aurais plutôt ajouté une propriété au controle TextBox existant du genre TextIsEmpty.

Commentaire de gillardg le 22/06/2009 17:42:29

si tu as 25 textbox ??

Commentaire de claudetom le 22/06/2009 21:02:57

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>
    ''' <param name="hint"></param>
    ''' <param name="picture"></param>
    ''' <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>

 Ajouter un commentaire


Discussions en rapport avec ce code source dans le forum

Provoquer une perte de focus d'un textbox [ par Omsey ] J'aimerai pouvoir provoquer la perte de focus d'un control TextBox ne connaissant pas le control suivant (donc pas de .SetFocus).J'ai trouvé la méthod copier-coller dans un control textbox [ par Vstall ] bonjour à tous,j'ai un petit probleme : j'ai développé un UserForm Excel sous VBE à l'interieur duquel j'y ai mis un control Textbox. Impossible d'y c Savoir le type d'un control [ par mighnion ] Bonjour les amis,voilà, je voudrais afficher dans une msgbox le type d'un control.je m'explique:j'ai dans ma form une textbox (text1) et un bouton (bo probléme de TextBox et Control Data [ par minimum_serious ] Bonjour,&nbsp;&nbsp;&nbsp;J'ai un controle data reli&#233; &#224; un textbox, mais le pblm c'est que d&#233;s que j'effectue une requ&#234;te sur le c NET: Comment imprimer le nom et indice d'un control [ par scubaduba ] Salut; J'ai voulu imprimer le nom d'un control (comme si c'est un textbox --&gt; TextBox, pas le nom que j'ai donne) avec son indice (c'est preferabl Selection du texte d'un control TextBox [ par LUSTRUCRU ] BonjourJe souhaite s&#233;lectionner automatiquement le texte en bleu (ou autre couleur)&nbsp;se trouvant dans un textbox (dans un UserForm&nbsp;sur E TextBox.Lines() dans un Control TextBox multiline.. [ par tinux ] Nouvelle question lool, cette fois-ci la source me pose des soucis ...Voilà, pourquoi la propriété Lines d'un Textbox ne marche pas quand c'est défini transparence d'un control sur un backgroundimage d'une form [ par Adn56 ] Re salut all,Comme dis dans le titre je n'arrive pas à faire en sorte qu'un control soit rendu transparent sur l'image d'arriére plan de la form ! Il control [ par keks ] Bonjour tout le monde,J'ai une Form qui contient une centaine TextBox. Existe-t-il un moyen de récupérer leur valeur dans une boucle plutôt que de tap Déclaration des plusieurs control avec le même nom [ par jpse ] Bonjour,        Je voudrais savoir si on peut déclarer dans le fichier desinger ( MaForm.designer) plusieur instance de control (textbox disons) et ap


Nos sponsors


Sondage...

CalendriCode

Février 2012
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
272829    

Consulter la suite du CalendriCode

Photothèque

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,718 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales