XL 2013 [Résolu] Problème d'affichage de labels dans une frame

Lone-wolf

XLDnaute Barbatruc
Bonjour à toutes et à tous

Suite à un exemple de Jacques Boisgontier, j'ai essaié diverses manières d'afficher des labels dans un contrôle frame pour pouvoir ensuite faire un scroll, mais sans succès. Dans le fichier joint, le label affiche la dernière colonne; j'ai vu aussi qu'on pouvait utiliser la propriété Move x, y, L, H, et même après avoir initialisé Set Lb = Fm.Controls.Add("Forms.Label.1", "Label" & i, True), aucun changement. La macro d'initialisation se trouve dans le module.
 

Pièces jointes

  • Textbox Intuitive.xlsm
    42.8 KB · Affichages: 44

Lone-wolf

XLDnaute Barbatruc
Bonjour Jacques :)

Et merci d'avoir répondu. J'ai vu le fichier et même (celui-ci). Mais dans mon fichier je n'utilise qu'une textbox pour faire une recherche intuitive.

J'ai adapté ceci à mon fichier

Set Lab = Me.Frame1.Controls.Add("Forms.Label.1")
Lab.Caption = Range(NomTableau).Offset(-1).Item(1, c)
Lab.Top = Y
Lab.Left = X
Lab.Height = 24
Lab.Width = Range(NomTableau).Columns(c).Width * 1#

Mais je ne vois que la dernière colonne, top left height et width ne sont pas pris en charge dans la liste. Pourtant avec ton formulaire il n'y a pas de problème. Je ne comprends pas.
 
Dernière édition:

Lone-wolf

XLDnaute Barbatruc
Bonjour Jacques, Le Forum :)

Comme je n'ai pas pu faire l'adaptation, je m'y suis pris autrement, en mettant une 2ème listbox. Le seul petit incovénient, c'est qu'il faut cliquer sur une ligne de la listbox (tableau) pour ne pas voir la barre horizontale de la listbox2. Pour afficher le formulaire, double-clic sur la feuille.
 

Pièces jointes

  • Textbox Intuitive.xlsm
    43.6 KB · Affichages: 40

youky(BJ)

XLDnaute Barbatruc
Bonjour Lone-wolf
j'ai regardé ton fichier je pensais avoir le scroll de la listbox avec la souris mais non pas prévu.
J'avais fait un fichier qui scrollait avec la souris sur une frame, je viens de l'essayer sur win10 et ca marche plus.
Bruno
 

Lone-wolf

XLDnaute Barbatruc
Bonsoir Jacques, Bruno :)

@BOISGONTIER : comme tu as pu le constater les labels sont décalés par rapport aux colonnes, j'ai essaié d'adapter avec la macro de job75, mais sans succès. C'est pour ça que j'ai mis une 2ème listbox.

VB:
'Auteur job75
Sub AutoSize_Columns()
    Set ListB = UserForm1.ListBox1
    Set Fm = UserForm1.Frame1
 
    On Error Resume Next
    With Sheets("Base")
        tb = .Range("a2:k" & .Range("k" & Rows.Count).End(xlUp).Row).Value
        Bd = .Range("a1:k1")
     
        For i = 1 To .UsedRange.Columns.Count
            NbrDeCol = i
        Next i
     
        Premlig = 2
        DernLig = .Range("a1:k1").End(xlDown).Row

        ReDim Tablo(Premlig To DernLig, 1 To NbrDeCol), LenCar(1 To NbrDeCol)
        For C = 1 To NbrDeCol: LenCar(C) = 0
            For L = Premlig To DernLig
                Z$ = .Cells(L, C): If IsNumeric(Z$) Then Z$ = Z$ & "    "
                Tablo(L, C) = .Cells(L, C): If Len(Z$) > LenCar(C) Then LenCar(C) = Len(Z$)
                If C = 4 Or C = 7 Then LenCar(C) = 0  'masque les colonnes choisies
            Next: Next
    End With

    FontName$ = "Arial": FontSize$ = 8: Taille$ = 6
    ColWidth$ = LenCar(1) * Taille: ListWith$ = LenCar(1) * Taille$

    For C = 2 To NbrDeCol
        ColWidth$ = ColWidth$ & ";" & (LenCar(C) * Taille$)
        ListWith$ = ListWith$ + (LenCar(C) * Taille$)
    Next

    ListWith$ = ListWith$ + 10    'pour l'ascenseur

    With ListB
        .Width = ListWith$ - 140    'en premier
        .ColumnCount = NbrDeCol
        .ColumnWidths = ColWidth$
        .Font.Size = FontSize
        .Font.Name = FontName$
        .List = tb
    End With
 
    'adapte l'userform
    UserForm1.Width = ListB.Width + 40   'idem mais pour le cadre de l'userform
    Fm.ScrollWidth = ListB.Width + 150
    'UserForm1.ListBox2 = ListB.Width    'idem mais pour le cadre de l'userform
    Fm.Width = ListB.Width + 3
    Fm.ScrollBars = 1
End Sub