cs_krafi
Messages postés48Date d'inscriptionmardi 11 juin 2002StatutMembreDernière intervention28 janvier 2006
-
13 nov. 2004 à 14:23
cs_CanisLupus
Messages postés3757Date d'inscriptionmardi 23 septembre 2003StatutMembreDernière intervention13 mars 2006
-
13 nov. 2004 à 18:10
Salut,
Comment peut-on savoir qu'un controle (label, textbox) est chargé sur une form ?, car je crée un label dynamiquement, lors de l'evenement click sur un bouton, et biensûr si je re click sur le bouton, une erreur me dit que le contrôle est déja chargé.
Public Sub AfficheMsg(LeMsg As String, f As Form, Style As String)
Si f.LblInfo pas chargé alors '<- Mon prob est ici
cs_CanisLupus
Messages postés3757Date d'inscriptionmardi 23 septembre 2003StatutMembreDernière intervention13 mars 200620 13 nov. 2004 à 18:10
Après une tite étude, voilà mon code qui peut pllaier à certains bugs du 1er :
Public Sub AfficheMsg(LeMsg As String, f As Form, Style As String)
Dim c As Control
Dim x As Integer
Dim test As Boolean
For Each c In f.Controls
If c.Name = "lblinfo" Then
test = True
On Error GoTo trt_error
If c.Index > x Then x = c.Index
On Error GoTo 0
End If
Next
If Not test Then
MsgBox "Le controle n'existe pas !"
Exit Sub
End If
Load f.lblinfo(x + 1) ' le controle existe et on en crée une nouvelle instance
With f.lblinfo(x + 1)
.Left = 0
.Top = 0
.Caption = LeMsg
.AutoSize = True
.Visible = True
End With
Exit Sub
trt_error:
MsgBox "Le controle existe mais ne fait pas partie d'un goupe de controles"
End Sub
cs_CanisLupus
Messages postés3757Date d'inscriptionmardi 23 septembre 2003StatutMembreDernière intervention13 mars 200620 13 nov. 2004 à 17:34
Salut, essaie ça :
Public Sub AfficheMsg(LeMsg As String, f As Form, Style As String)
Dim c As Control
Dim x As Integer
For Each c In f.Controls
If c.Name = "lblinfo" Then
If c.Index > x Then x = c.Index
End If
Next
If x = 0 Then Exit Sub ' le controle n'existe pas
Load f.lblinfo(x + 1) ' le controle existe et on en crée une nouvelle instance
With f.lblinfo(x + 1)
.Left = 0
.Top = 0
.Caption = LeMsg
.AutoSize = True
.Visible = True
End With
'Fin Si
End Sub