IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VB 6 et antérieur Discussion :

[VB6]Creer un autre TextBox à partir d'une Textbox Existante


Sujet :

VB 6 et antérieur

  1. #1
    Membre régulier
    Inscrit en
    Octobre 2004
    Messages
    277
    Détails du profil
    Informations forums :
    Inscription : Octobre 2004
    Messages : 277
    Points : 76
    Points
    76
    Par défaut [VB6]Creer un autre TextBox à partir d'une Textbox Existante
    Bonjour à tous,

    Est-ce qu'il est possible de créer une nouvelle TextBox à Partir d'une TextBox existante.

    Je m'explique : J'ai 1 TextBox "Text1(0)", J'aimerai créer un autre Text1(1). Comment pourrai-je faire avec du code VB?

    nb : je travaille en Visual Basic 6.0.

    Merci d'avance.

  2. #2
    Inactif  
    Avatar de jmfmarques
    Profil pro
    Inscrit en
    Décembre 2005
    Messages
    3 784
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2005
    Messages : 3 784
    Points : 4 674
    Points
    4 674
    Par défaut
    Tu devrais préciser :

    Au stade du développement ou à celui du "runtime" (dynamiquement) ?

  3. #3
    Membre régulier
    Inscrit en
    Octobre 2004
    Messages
    277
    Détails du profil
    Informations forums :
    Inscription : Octobre 2004
    Messages : 277
    Points : 76
    Points
    76
    Par défaut
    Lorsque je lance mon formulaire et que je met une valeur dans la Text1(0), j'aimerai que automatiquement lorsque je fait Tab, par exemple ,il y a une Text1(1) qui se cree.

    Merci d'avance.

  4. #4
    Rédacteur
    Avatar de jacma
    Profil pro
    Inscrit en
    Juillet 2002
    Messages
    612
    Détails du profil
    Informations personnelles :
    Âge : 79
    Localisation : France

    Informations forums :
    Inscription : Juillet 2002
    Messages : 612
    Points : 1 241
    Points
    1 241
    Par défaut
    Ta TextBox est un objet. Tu peut donc en créer des instances.

    Déclares une variable objet (ou control) et initialise la.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    Dim myControl as Control
    Set myControl = TaTextBox

  5. #5
    Membre régulier
    Inscrit en
    Octobre 2004
    Messages
    277
    Détails du profil
    Informations forums :
    Inscription : Octobre 2004
    Messages : 277
    Points : 76
    Points
    76
    Par défaut
    Non c'est pas ce que je veux.

    Je me reexplique:
    Dans un formulaire j'ai une TextBox "Text1(0)". Lorsque je fais Tab il y a une deuxième TextBox "Text1(1)" qui se crée automatiquement et ainsi de suite.

    Comment pourrai je faire?

    J'ai trouver un bout de code dans la faq vb :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
    Dim i As Long
    For i = 1 To 9 
        Load Text1(i)
        Text1(i).Top = Text1(i - 1).Top + Text1(0).Height + 60
        Text1(i).Visible = True
    Next
    Ce code je l'ai mis dans mon Load de mon formulaire. Et en mode création j'ai créer qu'un seul TextBox et grâce à ce code j'en crée 9 lorsque mon formulaire est ouvert. Mais moi je voudrais que se soit seulement quand je fait Tab sur ma premiere TextBox qui rajoute une autre TextBox.

    Merci d'avance.

  6. #6
    Inactif  
    Avatar de jmfmarques
    Profil pro
    Inscrit en
    Décembre 2005
    Messages
    3 784
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2005
    Messages : 3 784
    Points : 4 674
    Points
    4 674
    Par défaut
    il y a une deuxième TextBox "Text1(1)" qui se crée automatiquement et ainsi de suite
    Qui se crée ou qui, déjà existant, se charge ?

    Ton code me laisse penser qu'il ne s'agit pas d'une création...

  7. #7
    Membre régulier
    Inscrit en
    Octobre 2004
    Messages
    277
    Détails du profil
    Informations forums :
    Inscription : Octobre 2004
    Messages : 277
    Points : 76
    Points
    76
    Par défaut
    non qui se crée.

  8. #8
    Membre régulier
    Inscrit en
    Octobre 2004
    Messages
    277
    Détails du profil
    Informations forums :
    Inscription : Octobre 2004
    Messages : 277
    Points : 76
    Points
    76
    Par défaut
    Oui c'est ça.

  9. #9
    Expert éminent
    Avatar de ThierryAIM
    Homme Profil pro
    Inscrit en
    Septembre 2002
    Messages
    3 673
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 61
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Secteur : Industrie

    Informations forums :
    Inscription : Septembre 2002
    Messages : 3 673
    Points : 8 524
    Points
    8 524
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    Private Sub Text1_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyTab Then
        If Index = 9 Then Exit Sub
        Load Text1(Index + 1)
        Text1(Index + 1).Top = Text1(Index).Top + Text1(0).Height + 60
        Text1(Index + 1).Visible = True
        Text1(Index + 1).SetFocus
        End If
    End Sub
    Mais la touche TAB pose probleme, tu doit mettre la propriété TabStop à false dans ton text1(0)
    Sinon tu peux utiliser vbKeyReturn
    Vous vous posez une question, la réponse est peut-être ici :
    Toutes les FAQs VB
    Les Cours et Tutoriels VB6/VBScript
    Les Sources VB6


    Je ne réponds pas aux questions techniques par MP. Utilisez les forums. Merci de votre compréhension

  10. #10
    Expert éminent
    Avatar de ThierryAIM
    Homme Profil pro
    Inscrit en
    Septembre 2002
    Messages
    3 673
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 61
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Secteur : Industrie

    Informations forums :
    Inscription : Septembre 2002
    Messages : 3 673
    Points : 8 524
    Points
    8 524
    Par défaut
    Citation Envoyé par ouskel'n'or
    Créés en dynamique comme tu le fais, j'ignore s'il est possible de récupérer les événements qui te permettraient de passer de l'un à l'autre et donc de créer le suivant.
    Un controle créé dynamiquement à partir d'un autre est toujours WithEvents
    Dans ce cas, seule la touche TAB peut causer un soucis car c'est aussi une fonctionnalité Windows
    Pour contourner cela, il faut que TabStop soit à False, ce qui inhibe la fonction de passage d'un controle à l'autre
    Vous vous posez une question, la réponse est peut-être ici :
    Toutes les FAQs VB
    Les Cours et Tutoriels VB6/VBScript
    Les Sources VB6


    Je ne réponds pas aux questions techniques par MP. Utilisez les forums. Merci de votre compréhension

  11. #11
    Expert éminent
    Avatar de ThierryAIM
    Homme Profil pro
    Inscrit en
    Septembre 2002
    Messages
    3 673
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 61
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Secteur : Industrie

    Informations forums :
    Inscription : Septembre 2002
    Messages : 3 673
    Points : 8 524
    Points
    8 524
    Par défaut
    Je repète :
    Un controle créé dynamiquement à partir d'un autre est toujours WithEvents
    Vous vous posez une question, la réponse est peut-être ici :
    Toutes les FAQs VB
    Les Cours et Tutoriels VB6/VBScript
    Les Sources VB6


    Je ne réponds pas aux questions techniques par MP. Utilisez les forums. Merci de votre compréhension

  12. #12
    Membre régulier
    Homme Profil pro
    Conseil - Consultant en systèmes d'information
    Inscrit en
    Avril 2005
    Messages
    64
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Conseil - Consultant en systèmes d'information
    Secteur : Conseil

    Informations forums :
    Inscription : Avril 2005
    Messages : 64
    Points : 95
    Points
    95
    Par défaut
    salut
    voila ce que j'ai put faire :
    mettre la propriété TabStop du textbox à false
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    Option Explicit
     
     
    Dim mShift As Integer
     
    Private Sub Text1_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)
       mShift = Shift
    End Sub
     
    Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)
    Dim i As Long
       If KeyAscii = vbKeyTab And mShift = 0 Then
          If Index = Text1.Count - 1 Then
             i = Text1.Count
             Load Text1(i)
             Text1(i).Top = Text1(i - 1).Top + Text1(0).Height + 60
             Text1(i).Visible = True
             Text1(i).SetFocus
          Else
             i = Index + 1
             Text1(i).SetFocus
          End If
       ElseIf KeyAscii = vbKeyTab And mShift = 1 Then
          If Index = 0 Then
             i = Text1.Count - 1
          Else
             i = Index - 1
          End If
          Text1(i).SetFocus
       End If
    End Sub
     
    Private Sub Text1_KeyUp(Index As Integer, KeyCode As Integer, Shift As Integer)
       mShift = 0
    End Sub

  13. #13
    Inactif  
    Avatar de jmfmarques
    Profil pro
    Inscrit en
    Décembre 2005
    Messages
    3 784
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2005
    Messages : 3 784
    Points : 4 674
    Points
    4 674
    Par défaut
    Ce code je l'ai mis dans mon Load de mon formulaire
    puis-je timidement rappeler que l'événement load n'est pas du tout indiqué pour ce genre d'intervention (sur une Form non encore complétement chargée à coup sur) ??? : :

  14. #14
    Membre régulier
    Inscrit en
    Octobre 2004
    Messages
    277
    Détails du profil
    Informations forums :
    Inscription : Octobre 2004
    Messages : 277
    Points : 76
    Points
    76
    Par défaut
    J'ai mis ton code Amri_Daly mais il ne fonctionne pas.

    As-tu mis tout ton code? Ou si non, peux tu me dire ce que je doit rajouter?

    Merci d'avance.

  15. #15
    Membre régulier
    Inscrit en
    Octobre 2004
    Messages
    277
    Détails du profil
    Informations forums :
    Inscription : Octobre 2004
    Messages : 277
    Points : 76
    Points
    76
    Par défaut
    Non désolé cela marche.

    Mais je voudrais poser une question donc par exemple j'ai 4 TextBox : Text1(0), Text2(0), Text3(0) et Text4(0). Alors je tape differents informations dans les textBox à la suite, c'est à dire Text1(0), Text2(0), text3(0) et Text4(0) et que lorsque j'arrive à la Text4(0) il me met automatiquement la Text1(1), Text2(1), Text3(1) et La Text4(1) et Ainsi de suite?

  16. #16
    Membre régulier
    Inscrit en
    Octobre 2004
    Messages
    277
    Détails du profil
    Informations forums :
    Inscription : Octobre 2004
    Messages : 277
    Points : 76
    Points
    76
    Par défaut
    C'est bon je crois avoir trouver, je vous met le code :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
     
    Option Explicit
    Dim mShift As Integer
     
    Private Sub Text4_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)
     mShift = Shift
    End Sub
     
     
     
    Private Sub Text4_KeyPress(Index As Integer, KeyAscii As Integer)
    Dim i As Long
       If KeyAscii = vbKeyTab And mShift = 0 Then
          If Index = Text4.Count - 1 Then
             i = Text4.Count
             Load Text1(i)
             Load Text2(i)
             Load Text3(i)
             Load Text4(i)
             Text1(i).Top = Text1(i - 1).Top + Text1(0).Height + 60
             Text2(i).Top = Text2(i - 1).Top + Text2(0).Height + 60
             Text3(i).Top = Text3(i - 1).Top + Text3(0).Height + 60
             Text4(i).Top = Text4(i - 1).Top + Text4(0).Height + 60
             Text1(i).Visible = True
             Text2(i).Visible = True
             Text3(i).Visible = True
             Text4(i).Visible = True
             Text1(i).SetFocus
             Text2(i).SetFocus
             Text3(i).SetFocus
             Text4(i).SetFocus
          Else
             i = Index + 1
             Text1(i).SetFocus
             Text2(i).SetFocus
             Text3(i).SetFocus
             Text4(i).SetFocus
          End If
       ElseIf KeyAscii = vbKeyTab And mShift = 1 Then
          If Index = 0 Then
             i = Text4.Count - 1
          Else
             i = Index - 1
          End If
           Text1(i).SetFocus
             Text2(i).SetFocus
             Text3(i).SetFocus
             Text4(i).SetFocus
       End If
     
    End Sub
     
    Private Sub Text4_KeyUp(Index As Integer, KeyCode As Integer, Shift As Integer)
       mShift = 0
    End Sub
    Mais si quelqu'un à une autre méthode, il peut la faire part.

    A++

  17. #17
    Inactif  
    Avatar de jmfmarques
    Profil pro
    Inscrit en
    Décembre 2005
    Messages
    3 784
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2005
    Messages : 3 784
    Points : 4 674
    Points
    4 674
    Par défaut
    Tiens ??

    tous ces Setfocus à la suite me semblent pour le moins surprenants ...

    Alots, finalement, c'est le dernier Setfocus qui compte, non ? (mais tous les chemins mènent à Rome !)

    Bizarre, Bizarre...

  18. #18
    Membre régulier
    Inscrit en
    Octobre 2004
    Messages
    277
    Détails du profil
    Informations forums :
    Inscription : Octobre 2004
    Messages : 277
    Points : 76
    Points
    76
    Par défaut
    arf, c'est pas totalement bon car ben je ne peux pas faire Tab et donc je suis obligé de cliquer sur mes textbox.

    Car j'ai était obligé de mettre la propriété TabStop = false à toute les TextBox pour que lorsque je fais le Tab sur la text4(0) il me rajoute la ligne des textbox suivante : Text1(1), Text2(1), Text3(1), Text4(1).

    Pouvez-vous m'aider?
    Merci d'avance.

    A++

  19. #19
    Membre régulier
    Homme Profil pro
    Conseil - Consultant en systèmes d'information
    Inscrit en
    Avril 2005
    Messages
    64
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Conseil - Consultant en systèmes d'information
    Secteur : Conseil

    Informations forums :
    Inscription : Avril 2005
    Messages : 64
    Points : 95
    Points
    95
    Par défaut
    tu doit gérer toi même les tabulation :

    met la proprtiété de form "KeyPreview" à true
    remplace les évènements keyup et keydown de tous las contrôles textbox par :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
       mShift = Shift
    End Sub
     
    Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
       mShift = 0
    End Sub
    gère la tabulation avec l'évènement keypress des textbox :

    Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)
    If KeyAscii = vbKeyTab Then
    If mShift = 0 Then
    Text2(Index).SetFocus
    Else
    If Index = 0 Then
    Text4(Text1.Count - 1).SetFocus
    Else
    Text4(Index - 1).SetFocus
    End If
    End If
    End If
    End Sub

    Private Sub Text2_KeyPress(Index As Integer, KeyAscii As Integer)
    If KeyAscii = vbKeyTab Then
    If mShift = 0 Then
    Text3(Index).SetFocus
    Else
    Text1(Index).SetFocus
    End If
    End If

    End Sub

    Private Sub Text3_KeyPress(Index As Integer, KeyAscii As Integer)
    If KeyAscii = vbKeyTab Then
    If mShift = 0 Then
    Text4(Index).SetFocus
    Else
    Text2(Index).SetFocus
    End If
    End If
    End Sub
    pour les cettes focus dans la proc text4_keypress une seule suffira :
    Private Sub Text4_KeyPress(Index As Integer, KeyAscii As Integer)
    Dim i As Long
    If KeyAscii = vbKeyTab And mShift = 0 Then
    If Index = Text4.Count - 1 Then
    i = Text4.Count
    Load Text1(i)
    Load Text2(i)
    Load Text3(i)
    Load Text4(i)
    Text1(i).Top = Text1(i - 1).Top + Text1(0).Height + 60
    Text2(i).Top = Text2(i - 1).Top + Text2(0).Height + 60
    Text3(i).Top = Text3(i - 1).Top + Text3(0).Height + 60
    Text4(i).Top = Text4(i - 1).Top + Text4(0).Height + 60
    Text1(i).Visible = True
    Text2(i).Visible = True
    Text3(i).Visible = True
    Text4(i).Visible = True
    Text1(i).SetFocus
    Else
    i = Index + 1
    Text1(i).SetFocus
    End If
    ElseIf KeyAscii = vbKeyTab And mShift = 1 Then
    i = Index
    Text3(i).SetFocus
    End If

    End Sub
    A+

  20. #20
    Membre régulier
    Inscrit en
    Octobre 2004
    Messages
    277
    Détails du profil
    Informations forums :
    Inscription : Octobre 2004
    Messages : 277
    Points : 76
    Points
    76
    Par défaut
    Merci à tous et plus particulièrement à Amri_Daly qui m'a été d'un grand aide.

    Je vous met le code en entier pour ceux que ça intéresse :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
     
    Option Explicit
    Dim mShift As Integer
     
    Private Sub Text4_KeyPress(Index As Integer, KeyAscii As Integer)
    Dim i As Long
       If KeyAscii = vbKeyTab And mShift = 0 Then
          If Index = Text4.Count - 1 Then
             i = Text4.Count
             Load Text1(i)
             Load Text2(i)
             Load Text3(i)
             Load Text4(i)
             Text1(i).Top = Text1(i - 1).Top + Text1(0).Height + 60
             Text2(i).Top = Text2(i - 1).Top + Text2(0).Height + 60
             Text3(i).Top = Text3(i - 1).Top + Text3(0).Height + 60
             Text4(i).Top = Text4(i - 1).Top + Text4(0).Height + 60
             Text1(i).Visible = True
             Text2(i).Visible = True
             Text3(i).Visible = True
             Text4(i).Visible = True
             Text1(i).SetFocus
          Else
             i = Index + 1
             Text1(i).SetFocus
          End If
       ElseIf KeyAscii = vbKeyTab And mShift = 1 Then
          If Index = 0 Then
             i = Text4.Count - 1
          Else
             i = Index - 1
          End If
            Text3(i).SetFocus
       End If
     
    End Sub
     
     
    Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)
    If KeyAscii = vbKeyTab Then
    If mShift = 0 Then
    Text2(Index).SetFocus
    Else
    If Index = 0 Then
    Text4(Text1.Count - 1).SetFocus
    Else
    Text4(Index - 1).SetFocus
    End If
    End If
    End If
    End Sub
     
    Private Sub Text2_KeyPress(Index As Integer, KeyAscii As Integer)
    If KeyAscii = vbKeyTab Then
    If mShift = 0 Then
    Text3(Index).SetFocus
    Else
    Text1(Index).SetFocus
    End If
    End If
     
    End Sub
     
    Private Sub Text3_KeyPress(Index As Integer, KeyAscii As Integer)
    If KeyAscii = vbKeyTab Then
    If mShift = 0 Then
    Text4(Index).SetFocus
    Else
    Text2(Index).SetFocus
    End If
    End If
    End Sub
     
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
       mShift = Shift
    End Sub
     
    Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
       mShift = 0
    End Sub


    Merci encore et bonne chance à tous

+ Répondre à la discussion
Cette discussion est résolue.
Page 1 sur 2 12 DernièreDernière

Discussions similaires

  1. [AC-2010] Remplir une textbox à partir d'une listbox multicritères
    Par david89 dans le forum IHM
    Réponses: 11
    Dernier message: 21/09/2011, 01h06
  2. [vb6] remplir un textbox à partir d'une base de données
    Par lumbroso dans le forum VB 6 et antérieur
    Réponses: 4
    Dernier message: 16/09/2010, 21h34
  3. Réponses: 11
    Dernier message: 31/08/2010, 09h49
  4. Réponses: 3
    Dernier message: 08/08/2008, 13h05
  5. creer une autre table à partir d'une requete
    Par papou34 dans le forum Langage SQL
    Réponses: 2
    Dernier message: 15/02/2007, 22h42

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo