OVH Cloud OVH Cloud

Création de contrôle

4 réponses
Avatar
François Caron
Bonjour, j'ai trouver le code pour ajouter un contr=F4le=20
=E9tiquette dinamyquement.
Option Explicit

Dim MonLabel As Label

Private Sub Command1_Click()
Dim bytNbr As Byte
=20
Form1.Controls.Add "VB.Label", "NewLabel", Form1

Set MonLabel =3D Form1!NewLabel

For bytNbr =3D 0 To 4
With MonLabel
.Name =3D "Label" & CStr(bytNbr)
.Visible =3D True
.Top =3D 0
.Left =3D 0
.Width =3D 2000
.Height =3D 300
.Font.Size =3D 12
.Caption =3D "Ceci est mon label"
End With
Next bytNbr
End Sub


J'aimerais pouvoir rajouter plus d'un =E9tiquette=20
dynamiquement =E0 l'aide d'une boucle For.

Est-ce que quelqu'un peu m'aider ?

Merci
Fran=E7ois Caron

4 réponses

Avatar
François Picalausa
Bonjour/soir,

voir la faq, la solution par Index
http://faq.vb.free.fr/index.php?questionˆ

ou adapte ton code pour avoir:
Option Explicit

Dim MonLabel As Label

Private Sub Command1_Click()
Dim bytNbr As Byte

For bytNbr = 0 To 4

Set MonLabel = Form1.Controls.Add("VB.Label", "NewLabel" & bytNbr,
Form1)

With MonLabel
.Name = "Label" & CStr(bytNbr)
.Visible = True
.Top = 0
.Left = 0
.Width = 2000
.Height = 300
.Font.Size = 12
.Caption = "Ceci est mon label"
End With
Next bytNbr
End Sub

--
François Picalausa (MVP VB)
FAQ VB : http://faq.vb.free.fr
MSDN : http://msdn.microsoft.com


"François Caron" a écrit dans le message de
news:26c3e01c38ea9$e9e804e0$
Bonjour, j'ai trouver le code pour ajouter un contrôle
étiquette dinamyquement.
Option Explicit

Dim MonLabel As Label

Private Sub Command1_Click()
Dim bytNbr As Byte

Form1.Controls.Add "VB.Label", "NewLabel", Form1

Set MonLabel = Form1!NewLabel

For bytNbr = 0 To 4
With MonLabel
.Name = "Label" & CStr(bytNbr)
.Visible = True
.Top = 0
.Left = 0
.Width = 2000
.Height = 300
.Font.Size = 12
.Caption = "Ceci est mon label"
End With
Next bytNbr
End Sub


J'aimerais pouvoir rajouter plus d'un étiquette
dynamiquement à l'aide d'une boucle For.

Est-ce que quelqu'un peu m'aider ?

Merci
François Caron


Avatar
Zoury
Salut François! :O)

Le plus simple est de créer le premier Label sur ta page, invisible avec la
propriété Index égal à 0. Le reste est un jeu d'enfant.

'***
' Form1
' 1 Label, Visible = False, Index = 0
' 1 CommandButton
Option Explicit

Private Sub Command1_Click()

Dim i As Long

Label1(0).Visible = True
For i = 1 To 10
Call Load(Label1(i))
Label1(i).Top = Label1(i - 1).Top + Label1(i - 1).Height
Label1(i).Left = Label1(i - 1).Left
Label1(i).Visible = True
Next i

End Sub
'***

--
Cordialement
Yanick Lefebvre - MVP pour Visual Basic
http://faq.vb.free.fr/?rubrique=0 - http://www.mvps.org/vbnet/
http://www.mentalis.org/agnet/apiguide.shtml - http://www.mztools.com/

Merci de poster les réponses au groupe afin d'en faire profiter à tous
Avatar
François Caron
À la ligne ".Name = ...."
VB me dit:Impossible d'affecter à une propriété en lecture
seule.

Que faire ????
Merci pour votre aide
François Caron

-----Message d'origine-----
Bonjour/soir,

voir la faq, la solution par Index
http://faq.vb.free.fr/index.php?questionˆ

ou adapte ton code pour avoir:
Option Explicit

Dim MonLabel As Label

Private Sub Command1_Click()
Dim bytNbr As Byte

For bytNbr = 0 To 4

Set MonLabel = Form1.Controls.Add


("VB.Label", "NewLabel" & bytNbr,
Form1)

With MonLabel
.Name = "Label" & CStr(bytNbr)
.Visible = True
.Top = 0
.Left = 0
.Width = 2000
.Height = 300
.Font.Size = 12
.Caption = "Ceci est mon label"
End With
Next bytNbr
End Sub

--
François Picalausa (MVP VB)
FAQ VB : http://faq.vb.free.fr
MSDN : http://msdn.microsoft.com


"François Caron" a écrit dans le


message de
news:26c3e01c38ea9$e9e804e0$
Bonjour, j'ai trouver le code pour ajouter un contrôle
étiquette dinamyquement.
Option Explicit

Dim MonLabel As Label

Private Sub Command1_Click()
Dim bytNbr As Byte

Form1.Controls.Add "VB.Label", "NewLabel", Form1

Set MonLabel = Form1!NewLabel

For bytNbr = 0 To 4
With MonLabel
.Name = "Label" & CStr(bytNbr)
.Visible = True
.Top = 0
.Left = 0
.Width = 2000
.Height = 300
.Font.Size = 12
.Caption = "Ceci est mon label"
End With
Next bytNbr
End Sub


J'aimerais pouvoir rajouter plus d'un étiquette
dynamiquement à l'aide d'une boucle For.

Est-ce que quelqu'un peu m'aider ?

Merci
François Caron




.



Avatar
lolo
la propriété est en lecture seule, tu n'y touche pas
voici un exemple d'une de mes appli. le code suivant crée
des menus destiné à être affiché en popupmenu :

Set DB = OpenDatabase(MaBase, False, False, sConnect)
Set RS = DB.OpenRecordset("SELECT DISTINCT
unite_pedagogique FROM classe ORDER BY unite_pedagogique")
iIndx = 1
While Not RS.EOF
Load mnuCocherUP(iIndx)
mnuCocherUP(iIndx).Caption = "Cocher les classes de
l'unité " & RS!unite_pedagogique
mnuCocherUP(iIndx).Visible = True

Load mnuDecocherUP(iIndx)
mnuDecocherUP(iIndx).Caption = "Décocher les classes
de l'unité " & RS!unite_pedagogique
mnuDecocherUP(iIndx).Visible = True
RS.MoveNext
iIndx = iIndx + 1
Wend
RS.Close

EXPLICATION:
j'ai créer en dur deux menu (mnuCocher, mnuDecocher) je
leur ai mis l'index=0. Tous les menus que je cré auront
la propriété name = mnuCocher OU mnuDecocher.
Tu distingueras tes menus par leur index :
mnuCocher(2).enabled par exemple.

Dans chaque évenement de mes menus il me met en paramétre
l'index du menu générant l'événement...

bon courage

-----Message d'origine-----
À la ligne ".Name = ...."
VB me dit:Impossible d'affecter à une propriété en


lecture
seule.

Que faire ????
Merci pour votre aide
François Caron

-----Message d'origine-----
Bonjour/soir,

voir la faq, la solution par Index
http://faq.vb.free.fr/index.php?questionˆ

ou adapte ton code pour avoir:
Option Explicit

Dim MonLabel As Label

Private Sub Command1_Click()
Dim bytNbr As Byte

For bytNbr = 0 To 4

Set MonLabel = Form1.Controls.Add


("VB.Label", "NewLabel" & bytNbr,
Form1)

With MonLabel
.Name = "Label" & CStr(bytNbr)
.Visible = True
.Top = 0
.Left = 0
.Width = 2000
.Height = 300
.Font.Size = 12
.Caption = "Ceci est mon label"
End With
Next bytNbr
End Sub

--
François Picalausa (MVP VB)
FAQ VB : http://faq.vb.free.fr
MSDN : http://msdn.microsoft.com


"François Caron" a écrit dans le


message de
news:26c3e01c38ea9$e9e804e0$
Bonjour, j'ai trouver le code pour ajouter un contrôle
étiquette dinamyquement.
Option Explicit

Dim MonLabel As Label

Private Sub Command1_Click()
Dim bytNbr As Byte

Form1.Controls.Add "VB.Label", "NewLabel", Form1

Set MonLabel = Form1!NewLabel

For bytNbr = 0 To 4
With MonLabel
.Name = "Label" & CStr(bytNbr)
.Visible = True
.Top = 0
.Left = 0
.Width = 2000
.Height = 300
.Font.Size = 12
.Caption = "Ceci est mon label"
End With
Next bytNbr
End Sub


J'aimerais pouvoir rajouter plus d'un étiquette
dynamiquement à l'aide d'une boucle For.

Est-ce que quelqu'un peu m'aider ?

Merci
François Caron




.



.