' il faut ajouter manuellement un label
' et dans index mettre 0
Private Sub Form_Load()
Dim m_counter As Long
Dim num As Long
num = 5 ' 5 labels
For m_counter = 1 To num
Call Load(Label1(m_counter))
Label1(m_counter).Caption = "Label " + Str(m_counter + 1)
Label1(m_counter).Width = Label1(m_counter - 1).Width
Label1(m_counter).Height = Label1(m_counter - 1).Height
Label1(m_counter).Left = Label1(m_counter - 1).Left + Label1(m_counter - 1).Width + 20
Label1(m_counter).Visible = True
Next m_counter
End Sub
Const SW_NORMAL = 1
Private Const WS_VISIBLE = &H10000000
Private Const WS_CHILD = &H40000000
Private Declare Function CreateWindowEx Lib "user32" Alias "CreateWindowExA" (ByVal dwExStyle As Long, ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As Long, ByVal hMenu As Long, ByVal hInstance As Long, lpParam As Any) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Sub CreateDynLabel(ByVal posx As Long, ByVal posy As Long, ByVal width As Long, ByVal height As Long, ByVal title As String)
Dim m_hWnd As Long
m_hWnd = CreateWindowEx(ByVal 0&, "STATIC", title, WS_CHILD, posx, posy, width, height, Me.hwnd, ByVal 0&, App.hInstance, ByVal 0&)
Call ShowWindow(m_hWnd, SW_NORMAL)
End Sub
Private Sub Form_Load()
Dim m_counter As Long
Dim m_initialposx As Long
Dim m_initialposy As Long
m_initialposx = 20
m_initialposy = 20
For m_counter = 1 To 5
Call CreateDynLabel(m_initialposx, m_initialposy, 70, 50, "Label Dynamique " + Str(m_counter))
m_initialposx = m_initialposx + 100
Next m_counter
End Sub
Oui c'est tres bancal comme solution, et ca ne crée pas un vrai controle VB, donc bonjour les soucis par la suite (encore, pour un label c'est vrai que ca va a peu pres, mais pour un bouton ou autre, ca devient vite la galere).KarLKoX a écrit:
Si tu veux faire réagir les clicks de souris sur les labels, il faudra sous classer ta form et créer une fonction de rappel, répondre aux message windows (le wParam de WM_COMMAND), bref, c'est la fête de la saucisses et l'utilisation des winapi
Dernières astuces
Dernières questions
Forum Hardware
Forum Logiciels
