Option Explicit Private Sub UserForm_Initialize() Dim i As Integer, monTop As Single, monLeft As Single Me.Height = 450 Me.Width = 420 Set monUsf = Me 'ligne indispensable For i = 0 To 3 monTop = IIf(i < 2, 5, 205) monLeft = IIf(i And 1, 205, 5) maList(i).Affiche i, monLeft, monTop, 200, 200 'ligne indispensable Next End Sub
Option Explicit Public monUsf As Object Public maList(3) As New mListBox
Option Explicit Public WithEvents mTextB As MSForms.TextBox 'événements des textbox Public WithEvents mListB As MSForms.ListBox 'événements des listbox Private mLeft As Single, mTop As Single Private Sub Class_Initialize() 'Un objet "mListBox" est composé de trois contrôles : '- 1 listbox appelée "mListBox_" & Num '- 1 Frame appelé "mFrame_" & Num '- 1 textbox appelé "mTextBox_" & Num End Sub Sub Affiche(ByVal Num As Integer, ByVal L As Single, ByVal T As Single, ByVal W As Single, ByVal H As Single) 'dessine les 3 contrôles composant l'objet mListBox dans l'userform (monUsf) 'et affecte les propriétés événementielles (mListB et mTextB) Dim ListB As Object, TextB As Object, Frme As Object 'ajout du contrôle ListBox Set ListB = monUsf.Controls.Add("forms.ListBox.1") Set maList(Num).mListB = ListB With ListB .Move L, T, W, H .Name = "mListBox_" & Num End With 'Ajout du contrôle Frame Set Frme = monUsf.Controls.Add("forms.Frame.1") With Frme .Visible = False .Name = "mFrame_" & Num .Move L, T + H, 50, 20 .BorderStyle = 0 End With 'ajout du contrôle TextBox Set TextB = Frme.Controls.Add("forms.TextBox.1") Set maList(Num).mTextB = TextB With TextB .Name = "mTextBox_" & Num .Move 0, 0, 46, 16 End With 'libération des variables Set ListB = Nothing Set Frme = Nothing Set TextB = Nothing End Sub Private Sub mListB_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single) 'événement MouseDown du contrôle listbox '=> Si Frame.Visible Alors on passe la valeur du textbox dans la listbox 'puis (dans tous les cas) on affiche le Frame Dim Num As Integer 'si clic gauche If Button = 1 Then 'on récupère le numéro de la mListBox Num = CInt(Split(mListB.Name, "_")(1)) 'interception de la sortie du textbox par la souris If monUsf.Controls("mFrame_" & Num).Visible = True Then 'on enregistre la saisie du textbox dans la listbox Call Corrige_Liste(monUsf.Controls("mTextBox_" & Num).Value, X, Y) End If 'stockage des X et Y pour préparer la restitution des données lors de la sortie du textbox mLeft = X mTop = Y 'on affiche le Frame au bon endroit Affiche_Frame Num, True, X, Y End If End Sub Private Sub Affiche_Frame(ByVal Num As Integer, ByVal Visib As Boolean, ByVal X As Single, ByVal Y As Single) 'changement de la propriété Visible du Frame (=> Affichage vrai ou faux au bon endroit) With monUsf.Controls("mFrame_" & Num) .Visible = Visib 'rend visible ou invisible le Frame 'positionne le Frame en fonction du numéro .Move monUsf.Controls(mListB.Name).Left + X, monUsf.Controls(mListB.Name).Top + Y, .Width, .Height 'Positionne le Frame par dessus la ListBox .ZOrder msoBringToFront 'si visible attribue le focus au textbox If Visib Then .Controls("mTextBox_" & Num).SetFocus End With End Sub Private Sub mTextB_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) 'interception de la sortie du textbox par le clavier Dim Num As Integer 'quel textbox? Num = CInt(Split(mTextB.Name, "_")(1)) 'Qu'elle touche? Select Case Asc(UCase(Chr(KeyCode))) Case 9, 13 'touche TAB, Entrée Corrige_Liste mTextB.Value, mLeft, mTop 'Saisie de la valeur du textbox dans la listbox Affiche_Frame Num, False, 0, 0 'masque le Frame Case Else 'Autres End Select End Sub Private Sub Corrige_Liste(ByVal maVal As String, ByVal X As Single, ByVal Y As Single) 'passe mTextB.Value dans mListB End Sub Private Sub Class_Terminate() End Sub
Il est toujours possible de télécharger, enregistrer et utiliser MSFLEXGRID sous VBA.
Ce serait plus simple de faire ce que tu veux à partir de ce contrôle.
on va prendre le travail sur une listbox comme un défi.
Mais cela va être dur.
Si tu veux bien, dans ce cas, nous allons travailler pas à pas
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionPar contre, pas question de te laisser faire tout seul!
Je veux me "retrousser le code" également.
Je vais donc tenter, de mon côté, de suivre chaque étape et fournir un code systématiquement.
Option Explicit
Private ht As Integer, acacher As Integer, Lbord As Single
Private Sub Form_Activate()
Me.ScaleMode = vbPoints
Lbord = ScaleX(20, vbTwips, ScaleMode) ' ===>>> va falloir transposer (mon source)
Dim i As Integer
Set Font = List1.Font
ht = TextHeight("Coucou") '====>>> je vais devoir transposer (avec mon propre code du source que j'ai déposé)
For i = 1 To 20
List1.AddItem i & " aaa " & i
Next
End Sub
Private Sub List1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
acacher = List1.ListIndex
positionnons
End Sub
Private Sub List1_Scroll()
positionnons
End Sub
Private Sub positionnons()
Set Text1.Font = List1.Font
Text1.ForeColor = vbRed
Select Case List1.ListIndex
Case List1.TopIndex
Text1.Top = List1.Top
Case Else
Text1.Top = List1.Top + ((acacher - List1.TopIndex - 0) * ht) _
+ (Lbord * (List1.Appearance + 1))
End Select
Text1.Left = List1.Left + Lbord
Text1.Width = (List1.Width - Lbord * 2)
Text1.Height = ht
If Text1.Top >= List1.Top Then Text1.Visible = True Else Text1.Visible = False
Text1.ZOrder
End Sub
Lbord = ScaleX(20, vbTwips, ScaleMode) ' ===>>> va falloir transposer (mon source)
Lbord = 1
Bien (va falloir préparer l'aspirine).
Je ne reviendrai que ce soir, pour continuer.
Option Explicit Private Type hv X As Long Y As Long End Type Private Type LOGFONT lfHeight As Long lfWidth As Long lfEscapement As Long lfOrientation As Long lfWeight As Long lfItalic As Byte lfUnderline As Byte lfStrikeOut As Byte lfCharSet As Byte lfOutPrecision As Byte lfClipPrecision As Byte lfQuality As Byte lfPitchAndFamily As Byte lfFaceName As String * 32 End Type #If VBA7 Then Private Declare PtrSafe Function CreateDC Lib "gdi32.dll" Alias "CreateDCA" (ByVal lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As String, lpInitData As Long) As Long Private Declare PtrSafe Function CreateCompatibleBitmap Lib "gdi32.dll" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long Private Declare PtrSafe Function CreateFontIndirect Lib "gdi32.dll" Alias "CreateFontIndirectA" (lpLogFont As LOGFONT) As Long Private Declare PtrSafe Function SelectObject Lib "gdi32.dll" (ByVal hdc As Long, ByVal hObject As Long) As Long Private Declare PtrSafe Function DeleteObject Lib "gdi32.dll" (ByVal hObject As Long) As Long Private Declare PtrSafe Function MulDiv Lib "kernel32.dll" (ByVal nNumber As Long, ByVal nNumerator As Long, ByVal nDenominator As Long) As Long Private Declare PtrSafe Function GetDC Lib "user32.dll" (ByVal hwnd As Long) As Long Private Declare PtrSafe Function GetDeviceCaps Lib "gdi32.dll" (ByVal hdc As Long, ByVal nIndex As Long) As Long Private Declare PtrSafe Function DeleteDC Lib "gdi32.dll" (ByVal hdc As Long) As Long Private Declare PtrSafe Function GetTextExtentPoint32 Lib "gdi32" Alias "GetTextExtentPoint32A" (ByVal hdc As Long, ByVal lpsz As String, ByVal cbString As Long, lpSize As hv) As Long Private Declare PtrSafe Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long #Else Private Declare Function CreateDC Lib "gdi32.dll" Alias "CreateDCA" (ByVal lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As String, lpInitData As Long) As Long Private Declare Function CreateCompatibleBitmap Lib "gdi32.dll" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long Private Declare Function CreateFontIndirect Lib "gdi32.dll" Alias "CreateFontIndirectA" (lpLogFont As LOGFONT) As Long Private Declare Function SelectObject Lib "gdi32.dll" (ByVal hdc As Long, ByVal hObject As Long) As Long Private Declare Function DeleteObject Lib "gdi32.dll" (ByVal hObject As Long) As Long Private Declare Function MulDiv Lib "kernel32.dll" (ByVal nNumber As Long, ByVal nNumerator As Long, ByVal nDenominator As Long) As Long Private Declare Function GetDC Lib "user32.dll" (ByVal hwnd As Long) As Long Private Declare Function GetDeviceCaps Lib "gdi32.dll" (ByVal hdc As Long, ByVal nIndex As Long) As Long Private Declare Function DeleteDC Lib "gdi32.dll" (ByVal hdc As Long) As Long Private Declare Function GetTextExtentPoint32 Lib "gdi32" Alias "GetTextExtentPoint32A" (ByVal hdc As Long, ByVal lpsz As String, ByVal cbString As Long, lpSize As hv) As Long Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long #End If Private vba_font As New StdFont Private Const vbapoints As Integer = 20 Private Const vbapixels As Integer = 999 ' n'importe quoi sauf les autres valeurs Private Const vbainches As Integer = 1440 Private Const vbatwips As Integer = 1 Private Const vbaCharacters As Integer = 120 Private Const coeff As Single = 1.333333333333 Private mHeight As Single, mWidth As Single Private Sub UserForm_Initialize() Dim i As Integer With Me.Frame1 .Visible = False .Caption = "" .BorderStyle = fmBorderStyleNone End With ListBox1.Font.Size = 19 Set vba_font = ListBox1.Font mHeight = vba_TextHeight("Coucou", vba_font) For i = 1 To 100 ListBox1.AddItem i & " aaa " & i Next End Sub Private Sub ListBox1_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single) positionnons End Sub Private Sub positionnons() With Frame1 .Top = ListBox1.Top + (ListBox1.ListIndex - ListBox1.TopIndex) * (mHeight / coeff) .Left = ListBox1.Left + 1 .Width = (ListBox1.Width - 2) .Height = (mHeight / coeff) + ListBox1.SpecialEffect + 1 If .Top >= ListBox1.Top Then .Visible = True Else .Visible = False .ZOrder .TextBox1.Font.Size = ListBox1.Font.Size .TextBox1.Move 0, 0, Frame1.Width - 2, Frame1.Height - 2 End With End Sub Private Function vba_TextWidth(texte As String, la_font As StdFont) As Single vba_TextWidth = dimt(texte, la_font).X End Function Private Function vba_TextHeight(texte As String, la_font As StdFont) As Single vba_TextHeight = dimt(texte, la_font).Y End Function Private Function dimt(ch As String, ByVal pol As StdFont) As hv Dim cdc As Long, ccb As Long, cfi As Long, lgf As LOGFONT, tch As hv cdc = CreateDC("DISPLAY", "", "", ByVal 0) ccb = CreateCompatibleBitmap(cdc, 1, 1) DeleteObject SelectObject(cdc, ccb) lgf.lfFaceName = pol.Name & Chr$(0): lgf.lfHeight = -MulDiv(pol.Size, GetDeviceCaps(GetDC(0), 90), 72) lgf.lfItalic = pol.Italic: lgf.lfStrikeOut = pol.Strikethrough: lgf.lfUnderline = pol.Underline lgf.lfWeight = 400 If pol.Bold = True Then lgf.lfWeight = lgf.lfWeight * 2 cfi = CreateFontIndirect(lgf) DeleteObject SelectObject(cdc, cfi) GetTextExtentPoint32 cdc, ch, Len(ch), tch DeleteObject cfi: DeleteDC cdc: DeleteObject ccb dimt = tch End Function
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Const SM_CYVSCROLL = 20 'hauteur d'une flèche d'ascenseur vertical
Const SM_CXHSCROLL = 21 'largeur d'une flèche d'ascenseur vertical
Private Sub CommandButton1_Click()
MsgBox "largeur de la flèche : " & Str$(GetSystemMetrics(SM_CXHSCROLL))
End Sub
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Const SM_CYVSCROLL = 20 'hauteur d'une flèche d'ascenseur vertical
Const SM_CXHSCROLL = 21 'largeur d'une flèche d'ascenseur vertical
Const SM_CXBORDER = 5
Private Sub CommandButton1_Click()
toto = Val(Str$(GetSystemMetrics(SM_CXBORDER))) * 2
toto = toto + (Val(Str$(GetSystemMetrics(SM_CXHSCROLL))) + toto)
MsgBox "largeur de l'ascensuer : " & toto & " pixels" & vbCrLf & _
" et donc ====> " & toto / 1.33333 & " points"
End Sub
Option Explicit
Private Type hv
X As Long
Y As Long
End Type
Private Type LOGFONT
lfHeight As Long
lfWidth As Long
lfEscapement As Long
lfOrientation As Long
lfWeight As Long
lfItalic As Byte
lfUnderline As Byte
lfStrikeOut As Byte
lfCharSet As Byte
lfOutPrecision As Byte
lfClipPrecision As Byte
lfQuality As Byte
lfPitchAndFamily As Byte
lfFaceName As String * 32
End Type
#If VBA7 Then
Private Declare PtrSafe Function CreateDC Lib "gdi32.dll" Alias "CreateDCA" (ByVal lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As String, lpInitData As Long) As Long
Private Declare PtrSafe Function CreateCompatibleBitmap Lib "gdi32.dll" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Private Declare PtrSafe Function CreateFontIndirect Lib "gdi32.dll" Alias "CreateFontIndirectA" (lpLogFont As LOGFONT) As Long
Private Declare PtrSafe Function SelectObject Lib "gdi32.dll" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare PtrSafe Function DeleteObject Lib "gdi32.dll" (ByVal hObject As Long) As Long
Private Declare PtrSafe Function MulDiv Lib "kernel32.dll" (ByVal nNumber As Long, ByVal nNumerator As Long, ByVal nDenominator As Long) As Long
Private Declare PtrSafe Function GetDC Lib "user32.dll" (ByVal hwnd As Long) As Long
Private Declare PtrSafe Function GetDeviceCaps Lib "gdi32.dll" (ByVal hdc As Long, ByVal nIndex As Long) As Long
Private Declare PtrSafe Function DeleteDC Lib "gdi32.dll" (ByVal hdc As Long) As Long
Private Declare PtrSafe Function GetTextExtentPoint32 Lib "gdi32" Alias "GetTextExtentPoint32A" (ByVal hdc As Long, ByVal lpsz As String, ByVal cbString As Long, lpSize As hv) As Long
Private Declare PtrSafe Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
#Else
Private Declare Function CreateDC Lib "gdi32.dll" Alias "CreateDCA" (ByVal lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As String, lpInitData As Long) As Long
Private Declare Function CreateCompatibleBitmap Lib "gdi32.dll" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Private Declare Function CreateFontIndirect Lib "gdi32.dll" Alias "CreateFontIndirectA" (lpLogFont As LOGFONT) As Long
Private Declare Function SelectObject Lib "gdi32.dll" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteObject Lib "gdi32.dll" (ByVal hObject As Long) As Long
Private Declare Function MulDiv Lib "kernel32.dll" (ByVal nNumber As Long, ByVal nNumerator As Long, ByVal nDenominator As Long) As Long
Private Declare Function GetDC Lib "user32.dll" (ByVal hwnd As Long) As Long
Private Declare Function GetDeviceCaps Lib "gdi32.dll" (ByVal hdc As Long, ByVal nIndex As Long) As Long
Private Declare Function DeleteDC Lib "gdi32.dll" (ByVal hdc As Long) As Long
Private Declare Function GetTextExtentPoint32 Lib "gdi32" Alias "GetTextExtentPoint32A" (ByVal hdc As Long, ByVal lpsz As String, ByVal cbString As Long, lpSize As hv) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
#End If
Private vba_font As New StdFont
Private Const vbapoints As Integer = 20
Private Const vbapixels As Integer = 999 ' n'importe quoi sauf les autres valeurs
Private Const vbainches As Integer = 1440
Private Const vbatwips As Integer = 1
Private Const vbaCharacters As Integer = 120
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Const SM_CYVSCROLL = 20 'hauteur d'une flèche d'ascenseur vertical
Const SM_CXHSCROLL = 21 'largeur d'une flèche d'ascenseur vertical
Const SM_CXBORDER = 5
Private Const coeff As Single = 1.333333333333
Private mHeight As Single, mWidth As Single, bord As Single
Private Sub ListBox1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
'Label1.Caption = Y
End Sub
Private Sub ScrollBar1_Change()
ListBox1.TopIndex = ScrollBar1.Value
positionnons
End Sub
Private Sub ScrollBar1_Scroll()
ListBox1.TopIndex = ScrollBar1.Value
positionnons
End Sub
Private Sub TextBox1_Change()
ListBox1.List(ListBox1.ListIndex) = TextBox1.Text
End Sub
Private Sub UserForm_Initialize()
Dim i As Integer, lAscLst As Single, lfleche As Single
bord = GetSystemMetrics(SM_CXBORDER) / 1.3333
lfleche = GetSystemMetrics(SM_CXHSCROLL) / 1.3333
lAscLst = (bord + bord + lfleche)
With Me.Frame1
.Visible = False
.Caption = ""
.BorderStyle = fmBorderStyleNone
End With
ListBox1.Font.Size = 11
'ListBox1.SpecialEffect = 1
Set vba_font = ListBox1.Font
With vba_font
.Bold = ListBox1.Font.Bold
.Italic = ListBox1.Font.Italic
End With
mHeight = vba_TextHeight("Coucou", vba_font)
For i = 1 To 100
ListBox1.AddItem i & " aaa " & i
Next
Dim corr_effect As Integer
corr_effect = IIf(ListBox1.SpecialEffect = 0, 1, 0)
With TextBox1
.ForeColor = vbRed
.Move 0, -bord - bord - corr_effect, Frame1.Width - bord - bord, Frame1.Height - (bord * 2)
.Font.Size = ListBox1.Font.Size
.Font.Bold = ListBox1.Font.Bold
.Font.Italic = ListBox1.Font.Italic
End With
With Frame2
.Caption = ""
.BorderStyle = fmBorderStyleNone
.Move ListBox1.Left + ListBox1.Width - lAscLst, ListBox1.Top, lAscLst, ListBox1.Height
.ZOrder
End With
With ScrollBar1
.SmallChange = 1
.LargeChange = 1
.Move 0, 0, Frame2.Width - (bord * 4), Frame2.Height - (bord * 2)
.Max = ListBox1.Height
.Value = 0
.Min = 0
.ZOrder
End With
End Sub
Private Sub ListBox1_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
positionnons
TextBox1.SetFocus
End Sub
Private Sub positionnons()
If ListBox1.ListIndex >= 0 Then TextBox1.Text = ListBox1.List(ListBox1.ListIndex)
Dim corr_effect As Byte
With Frame1
.Top = ListBox1.Top + (ListBox1.ListIndex - ListBox1.TopIndex) * (mHeight / coeff) '+ 1
.Left = ListBox1.Left + bord
.Width = (ListBox1.Width - (bord * 2)) - ScrollBar1.Width
If ListBox1.SpecialEffect = 0 Then corr_effect = 1 Else corr_effect = ListBox1.SpecialEffect
.Height = (mHeight / coeff) + corr_effect + (bord * 1)
If .Top >= ListBox1.Top And .Top <= ListBox1.Top + ListBox1.Height Then .Visible = True Else .Visible = False
.ZOrder
End With
End Sub
Private Function vba_TextWidth(texte As String, la_font As StdFont) As Single
vba_TextWidth = dimt(texte, la_font).X
End Function
Private Function vba_TextHeight(texte As String, la_font As StdFont) As Single
vba_TextHeight = dimt(texte, la_font).Y
End Function
Private Function dimt(ch As String, ByVal pol As StdFont) As hv
Dim cdc As Long, ccb As Long, cfi As Long, lgf As LOGFONT, tch As hv
cdc = CreateDC("DISPLAY", "", "", ByVal 0)
ccb = CreateCompatibleBitmap(cdc, 1, 1)
DeleteObject SelectObject(cdc, ccb)
lgf.lfFaceName = pol.Name & Chr$(0): lgf.lfHeight = -MulDiv(pol.Size, GetDeviceCaps(GetDC(0), 90), 72)
lgf.lfItalic = pol.Italic: lgf.lfStrikeOut = pol.Strikethrough: lgf.lfUnderline = pol.Underline
lgf.lfWeight = 400
If pol.Bold = True Then lgf.lfWeight = lgf.lfWeight * 2
cfi = CreateFontIndirect(lgf)
DeleteObject SelectObject(cdc, cfi)
GetTextExtentPoint32 cdc, ch, Len(ch), tch
DeleteObject cfi: DeleteDC cdc: DeleteObject ccb
dimt = tch
End Function
Private Sub UserForm_Activate()
ListBox1.ColumnCount = 3
ListBox1.ColumnWidths = "25;40;50"
ListBox1.Width = (25 + 40 + 50) + ListBox1.ColumnCount
For i = 0 To 20
For j = 0 To ListBox1.ColumnCount - 1
ListBox1.AddItem "aaaa"
ListBox1.List(i, j) = "b"
Next
Next
End Sub
Private Sub ListBox1_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Select Case X
Case Is >= 65
colonne = 2
Case Is >= 25
colonne = 1
Case Is >= 0
colonne = 0
End Select
MsgBox "tu a cliqué dans la colonne " & colonne & " de la ligne " & ListBox1.ListIndex
End Sub
Private Sub positionnons() Dim corr_effect As Byte With Frame1 .Top = ListBox1.Top + (ListBox1.ListIndex - ListBox1.TopIndex) * (mHeight / coeff) .Left = ListBox1.Left + 1 .Width = mWidth If ListBox1.SpecialEffect = 0 Then corr_effect = 1 Else corr_effect = ListBox1.SpecialEffect .Height = (mHeight / coeff) + corr_effect + (bord * 1) If .Top >= ListBox1.Top Then .Visible = True .ZOrder With .TextBox1 Set .Font = ListBox1.Font .Value = ListBox1.List(ListBox1.ListIndex) .SetFocus End With Else: .Visible = False End If End With End Sub
'-------GESTION MULTI-COLONNES
Option Explicit Private Type hv X As Long Y As Long End Type Private Type LOGFONT lfHeight As Long lfWidth As Long lfEscapement As Long lfOrientation As Long lfWeight As Long lfItalic As Byte lfUnderline As Byte lfStrikeOut As Byte lfCharSet As Byte lfOutPrecision As Byte lfClipPrecision As Byte lfQuality As Byte lfPitchAndFamily As Byte lfFaceName As String * 32 End Type #If VBA7 Then Private Declare PtrSafe Function CreateDC Lib "gdi32.dll" Alias "CreateDCA" (ByVal lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As String, lpInitData As Long) As Long Private Declare PtrSafe Function CreateCompatibleBitmap Lib "gdi32.dll" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long Private Declare PtrSafe Function CreateFontIndirect Lib "gdi32.dll" Alias "CreateFontIndirectA" (lpLogFont As LOGFONT) As Long Private Declare PtrSafe Function SelectObject Lib "gdi32.dll" (ByVal hdc As Long, ByVal hObject As Long) As Long Private Declare PtrSafe Function DeleteObject Lib "gdi32.dll" (ByVal hObject As Long) As Long Private Declare PtrSafe Function MulDiv Lib "kernel32.dll" (ByVal nNumber As Long, ByVal nNumerator As Long, ByVal nDenominator As Long) As Long Private Declare PtrSafe Function GetDC Lib "user32.dll" (ByVal hwnd As Long) As Long Private Declare PtrSafe Function GetDeviceCaps Lib "gdi32.dll" (ByVal hdc As Long, ByVal nIndex As Long) As Long Private Declare PtrSafe Function DeleteDC Lib "gdi32.dll" (ByVal hdc As Long) As Long Private Declare PtrSafe Function GetTextExtentPoint32 Lib "gdi32" Alias "GetTextExtentPoint32A" (ByVal hdc As Long, ByVal lpsz As String, ByVal cbString As Long, lpSize As hv) As Long Private Declare PtrSafe Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long Private Declare PtrSafe Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long #Else Private Declare Function CreateDC Lib "gdi32.dll" Alias "CreateDCA" (ByVal lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As String, lpInitData As Long) As Long Private Declare Function CreateCompatibleBitmap Lib "gdi32.dll" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long Private Declare Function CreateFontIndirect Lib "gdi32.dll" Alias "CreateFontIndirectA" (lpLogFont As LOGFONT) As Long Private Declare Function SelectObject Lib "gdi32.dll" (ByVal hdc As Long, ByVal hObject As Long) As Long Private Declare Function DeleteObject Lib "gdi32.dll" (ByVal hObject As Long) As Long Private Declare Function MulDiv Lib "kernel32.dll" (ByVal nNumber As Long, ByVal nNumerator As Long, ByVal nDenominator As Long) As Long Private Declare Function GetDC Lib "user32.dll" (ByVal hwnd As Long) As Long Private Declare Function GetDeviceCaps Lib "gdi32.dll" (ByVal hdc As Long, ByVal nIndex As Long) As Long Private Declare Function DeleteDC Lib "gdi32.dll" (ByVal hdc As Long) As Long Private Declare Function GetTextExtentPoint32 Lib "gdi32" Alias "GetTextExtentPoint32A" (ByVal hdc As Long, ByVal lpsz As String, ByVal cbString As Long, lpSize As hv) As Long Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long #End If Private Const vbapoints As Integer = 20 Private Const vbapixels As Integer = 999 ' n'importe quoi sauf les autres valeurs Private Const vbainches As Integer = 1440 Private Const vbatwips As Integer = 1 Private Const vbaCharacters As Integer = 120 Private Const SM_CYVSCROLL = 20 'hauteur d'une flèche d'ascenseur vertical Private Const SM_CXHSCROLL = 21 'largeur d'une flèche d'ascenseur vertical Private Const SM_CXBORDER = 5 Private Const coeff As Single = 1.333333333333 Private Const UNITE As String = " pt" Private mHeight As Single, mWidth() As Single, mLeft() As Single, bord As Single Private colonne As Byte Private vba_font As New StdFont Private Sub UserForm_Initialize() Dim i As Integer, j As Integer, corr_effect As Integer, Col As Integer bord = GetSystemMetrics(SM_CXBORDER) / 1.3333 '-------PROPRIETES FRAME1 With Me.Frame1 .Visible = False .Caption = "" .BorderStyle = fmBorderStyleNone End With '------------------------------ '-------GESTION HAUTEUR DE LIGNES en fonction POLICE ListBox1.Font.Size = 11 Set vba_font = ListBox1.Font With vba_font .Bold = ListBox1.Font.Bold .Italic = ListBox1.Font.Italic End With mHeight = vba_TextHeight("Coucou", vba_font) '------------------------------ '-------PROPRIETES ET REMPLISSAGE LISTBOX ListBox1.ColumnCount = 3 ListBox1.ColumnWidths = "50;40;50" For i = 0 To 50 ListBox1.AddItem "aaaa" For j = 1 To ListBox1.ColumnCount - 1 ListBox1.List(i, j) = "b" Next Next '------------------------------ '-------GESTION MULTI-COLONNES ReDim Preserve mLeft(ListBox1.ColumnCount - 1) ReDim Preserve mWidth(ListBox1.ColumnCount - 1) mLeft(0) = 1 If ListBox1.ColumnCount > 1 Then mWidth(0) = CSng(Replace(Split(ListBox1.ColumnWidths, ";")(Col), UNITE, "")) For Col = 1 To ListBox1.ColumnCount - 1 mLeft(Col) = CDbl(Replace(Split(ListBox1.ColumnWidths, ";")(Col - 1), UNITE, "")) + mLeft(Col - 1) + 1 mWidth(Col) = CSng(Replace(Split(ListBox1.ColumnWidths, ";")(Col), UNITE, "")) Next ListBox1.Width = mLeft(UBound(mLeft)) + ListBox1.ColumnCount Else If ListBox1.ListCount * (mHeight / coeff) > ListBox1.Height Then mWidth(0) = ListBox1.Width - Largeur_Scrollbar Else: mWidth(0) = ListBox1.Width - 2 End If End If '------------------------------ '-------PROPRIETES TEXTBOX1 corr_effect = IIf(ListBox1.SpecialEffect = 0, 1, 0) With TextBox1 .ForeColor = vbRed .Move 0, -(bord * 2) - corr_effect, Frame1.Width, Frame1.Height - (bord * 2) .Font.Size = ListBox1.Font.Size .Font.Bold = ListBox1.Font.Bold .Font.Italic = ListBox1.Font.Italic End With '------------------------------ End Sub Private Sub ListBox1_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single) 'enregistrement, à chaque "clic" souris, de la colonne Dim i As Integer For i = UBound(mLeft) To LBound(mLeft) Step -1 If X >= mLeft(i) Then colonne = i: Exit For Next i End Sub Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean) positionnons End Sub Private Sub ListBox1_Enter() 'GESTION DU SCROLL LISTBOX1 If Frame1.Visible Then Frame1.Visible = False End Sub Private Sub positionnons() Dim corr_effect As Byte With Frame1 .Top = ListBox1.Top + (ListBox1.ListIndex - ListBox1.TopIndex) * (mHeight / coeff) .Left = ListBox1.Left + 1 + mLeft(colonne) .Width = mWidth(colonne) If ListBox1.SpecialEffect = 0 Then corr_effect = 1 Else corr_effect = ListBox1.SpecialEffect .Height = (mHeight / coeff) + corr_effect + (bord * 1) If .Top >= ListBox1.Top Then .Visible = True .ZOrder With .TextBox1 Set .Font = ListBox1.Font .Value = ListBox1.List(ListBox1.ListIndex, colonne) .SetFocus End With Else: .Visible = False End If End With End Sub Private Function Largeur_Scrollbar() As Single Dim Larg As Single Larg = Val(Str$(GetSystemMetrics(SM_CXBORDER))) * 2 Larg = Larg + (Val(Str$(GetSystemMetrics(SM_CXHSCROLL))) + Larg) Largeur_Scrollbar = Larg / coeff End Function Private Function vba_TextHeight(texte As String, la_font As StdFont) As Single vba_TextHeight = dimt(texte, la_font).Y End Function Private Function dimt(ch As String, ByVal pol As StdFont) As hv Dim cdc As Long, ccb As Long, cfi As Long, lgf As LOGFONT, tch As hv cdc = CreateDC("DISPLAY", "", "", ByVal 0) ccb = CreateCompatibleBitmap(cdc, 1, 1) DeleteObject SelectObject(cdc, ccb) lgf.lfFaceName = pol.Name & Chr$(0): lgf.lfHeight = -MulDiv(pol.Size, GetDeviceCaps(GetDC(0), 90), 72) lgf.lfItalic = pol.Italic: lgf.lfStrikeOut = pol.Strikethrough: lgf.lfUnderline = pol.Underline lgf.lfWeight = 400 If pol.Bold = True Then lgf.lfWeight = lgf.lfWeight * 2 cfi = CreateFontIndirect(lgf) DeleteObject SelectObject(cdc, cfi) GetTextExtentPoint32 cdc, ch, Len(ch), tch DeleteObject cfi: DeleteDC cdc: DeleteObject ccb dimt = tch End Function
ListBox1.ColumnWidths = "2 cm; 3,5 cm;5 cm"il faudra alors penser à cette conversion. Rien de compliqué (quoique), mais à garder en tête.
ListBox1.ColumnCount = 3
ListBox1.ColumnWidths = "25;40;50"
MsgBox ListBox1.ColumnWidths
ListBox1.ColumnCount = 3
ListBox1.ColumnWidths = "25 cm;40 cm;50 cm"
MsgBox ListBox1.ColumnWidths
Option Explicit Private Type hv X As Long Y As Long End Type Private Type LOGFONT lfHeight As Long lfWidth As Long lfEscapement As Long lfOrientation As Long lfWeight As Long lfItalic As Byte lfUnderline As Byte lfStrikeOut As Byte lfCharSet As Byte lfOutPrecision As Byte lfClipPrecision As Byte lfQuality As Byte lfPitchAndFamily As Byte lfFaceName As String * 32 End Type #If VBA7 Then Private Declare PtrSafe Function CreateDC Lib "gdi32.dll" Alias "CreateDCA" (ByVal lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As String, lpInitData As Long) As Long Private Declare PtrSafe Function CreateCompatibleBitmap Lib "gdi32.dll" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long Private Declare PtrSafe Function CreateFontIndirect Lib "gdi32.dll" Alias "CreateFontIndirectA" (lpLogFont As LOGFONT) As Long Private Declare PtrSafe Function SelectObject Lib "gdi32.dll" (ByVal hdc As Long, ByVal hObject As Long) As Long Private Declare PtrSafe Function DeleteObject Lib "gdi32.dll" (ByVal hObject As Long) As Long Private Declare PtrSafe Function MulDiv Lib "kernel32.dll" (ByVal nNumber As Long, ByVal nNumerator As Long, ByVal nDenominator As Long) As Long Private Declare PtrSafe Function GetDC Lib "user32.dll" (ByVal hwnd As Long) As Long Private Declare PtrSafe Function GetDeviceCaps Lib "gdi32.dll" (ByVal hdc As Long, ByVal nIndex As Long) As Long Private Declare PtrSafe Function DeleteDC Lib "gdi32.dll" (ByVal hdc As Long) As Long Private Declare PtrSafe Function GetTextExtentPoint32 Lib "gdi32" Alias "GetTextExtentPoint32A" (ByVal hdc As Long, ByVal lpsz As String, ByVal cbString As Long, lpSize As hv) As Long Private Declare PtrSafe Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long Private Declare PtrSafe Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long #Else Private Declare Function CreateDC Lib "gdi32.dll" Alias "CreateDCA" (ByVal lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As String, lpInitData As Long) As Long Private Declare Function CreateCompatibleBitmap Lib "gdi32.dll" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long Private Declare Function CreateFontIndirect Lib "gdi32.dll" Alias "CreateFontIndirectA" (lpLogFont As LOGFONT) As Long Private Declare Function SelectObject Lib "gdi32.dll" (ByVal hdc As Long, ByVal hObject As Long) As Long Private Declare Function DeleteObject Lib "gdi32.dll" (ByVal hObject As Long) As Long Private Declare Function MulDiv Lib "kernel32.dll" (ByVal nNumber As Long, ByVal nNumerator As Long, ByVal nDenominator As Long) As Long Private Declare Function GetDC Lib "user32.dll" (ByVal hwnd As Long) As Long Private Declare Function GetDeviceCaps Lib "gdi32.dll" (ByVal hdc As Long, ByVal nIndex As Long) As Long Private Declare Function DeleteDC Lib "gdi32.dll" (ByVal hdc As Long) As Long Private Declare Function GetTextExtentPoint32 Lib "gdi32" Alias "GetTextExtentPoint32A" (ByVal hdc As Long, ByVal lpsz As String, ByVal cbString As Long, lpSize As hv) As Long Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long #End If Private Const vbapoints As Integer = 20 Private Const vbapixels As Integer = 999 ' n'importe quoi sauf les autres valeurs Private Const vbainches As Integer = 1440 Private Const vbatwips As Integer = 1 Private Const vbaCharacters As Integer = 120 Private Const SM_CYVSCROLL = 20 'hauteur d'une flèche d'ascenseur vertical Private Const SM_CXHSCROLL = 21 'largeur d'une flèche d'ascenseur vertical Private Const SM_CYHSCROLL = 3 'hauteur d'une barre de défilement horizontale Private Const SM_CXBORDER = 5 Private Const COEFF As Single = 1.333333333333 Private mHeight As Single, mWidth() As Single, mLeft() As Single, bord As Single Private colonne As Byte Private vba_font As New StdFont Private Sub UserForm_Initialize() Dim i As Integer, j As Integer, corr_effect As Integer, Col As Integer Dim echelle As String, largeurs(), strColWidths As String, oldListWidth As Double bord = GetSystemMetrics(SM_CXBORDER) / COEFF '-------PROPRIETES FRAME1 With Me.Frame1 .Visible = False .Caption = "" .BorderStyle = fmBorderStyleNone End With '------------------------------ '-------GESTION HAUTEUR DE LIGNES en fonction POLICE ListBox1.Font.Size = 11 Set vba_font = ListBox1.Font With vba_font .Bold = ListBox1.Font.Bold .Italic = ListBox1.Font.Italic End With mHeight = vba_TextHeight("Coucou", vba_font) '------------------------------ '-------PROPRIETES ET REMPLISSAGE LISTBOX oldListWidth = ListBox1.Width ListBox1.ColumnCount = 3 echelle = " cm" largeurs = Array(3, 2, 4) strColWidths = largeurs(0) For i = 1 To UBound(largeurs) strColWidths = strColWidths & echelle & ";" & largeurs(i) Next ListBox1.ColumnWidths = strColWidths & " " & echelle '-------GESTION MULTI-COLONNES ReDim Preserve mLeft(ListBox1.ColumnCount - 1) ReDim Preserve mWidth(ListBox1.ColumnCount - 1) mLeft(0) = 1 If ListBox1.ColumnCount > 1 Then mWidth(0) = CSng(Replace(Split(ListBox1.ColumnWidths, ";")(0), " pt", "")) For Col = 1 To ListBox1.ColumnCount - 1 mLeft(Col) = CDbl(Replace(Split(ListBox1.ColumnWidths, ";")(Col - 1), " pt", "")) + mLeft(Col - 1) mWidth(Col) = CSng(Replace(Split(ListBox1.ColumnWidths, ";")(Col), " pt", "")) Next ListBox1.Width = mLeft(UBound(mLeft)) + mWidth(UBound(mWidth)) + ListBox1.ColumnCount DoEvents Else If ListBox1.ListCount * (mHeight / COEFF) > ListBox1.Height Then mWidth(0) = ListBox1.Width - Largeur_Scrollbar Else: mWidth(0) = ListBox1.Width - 2 End If End If Me.Width = Me.Width + ListBox1.Width - oldListWidth '------------------------------ For i = 0 To 50 ListBox1.AddItem "aa " & i For j = 1 To ListBox1.ColumnCount - 1 ListBox1.List(i, j) = Chr(97 + j) & Chr(97 + j) & " - " & i Next Next '------------------------------ '-------PROPRIETES TEXTBOX1 corr_effect = IIf(ListBox1.SpecialEffect = 0, 1, 0) With TextBox1 .ForeColor = vbRed .Move 0, -(bord * 2) - corr_effect, Frame1.Width, Frame1.Height - (bord * 2) .Font.Size = ListBox1.Font.Size .Font.Bold = ListBox1.Font.Bold .Font.Italic = ListBox1.Font.Italic End With '------------------------------ End Sub Private Sub ListBox1_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single) 'enregistrement, à chaque "clic" souris, de la colonne Dim i As Integer For i = UBound(mLeft) To LBound(mLeft) Step -1 If X >= mLeft(i) Then colonne = i: Exit For Next i End Sub Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean) 'EVENEMENT DECLENCHEUR positionnons End Sub Private Sub ListBox1_Enter() 'GESTION DU SCROLL LISTBOX1 If Frame1.Visible Then Frame1.Visible = False End Sub Private Sub positionnons() Dim corr_effect As Byte With Frame1 .Top = ListBox1.Top + (ListBox1.ListIndex - ListBox1.TopIndex) * (mHeight / COEFF) .Left = ListBox1.Left + 1 + mLeft(colonne) .Width = IIf(colonne < ListBox1.ColumnCount - 1, mWidth(colonne), mWidth(colonne) - (GetSystemMetrics(SM_CXHSCROLL) / COEFF)) If ListBox1.SpecialEffect = 0 Then corr_effect = 1 Else corr_effect = ListBox1.SpecialEffect .Height = (mHeight / COEFF) + corr_effect + (bord * 1) If .Top >= ListBox1.Top Then .Visible = True .ZOrder With .TextBox1 Set .Font = ListBox1.Font .Value = ListBox1.List(ListBox1.ListIndex, colonne) .Width = Frame1.Width .SetFocus End With Else: .Visible = False End If End With End Sub Private Function Largeur_Scrollbar() As Single Dim Larg As Single Larg = Val(Str$(GetSystemMetrics(SM_CXBORDER))) * 2 Larg = Larg + (Val(Str$(GetSystemMetrics(SM_CXHSCROLL))) + Larg) Largeur_Scrollbar = Larg / COEFF End Function Private Function vba_TextHeight(texte As String, la_font As StdFont) As Single vba_TextHeight = dimt(texte, la_font).Y End Function Private Function dimt(ch As String, ByVal pol As StdFont) As hv Dim cdc As Long, ccb As Long, cfi As Long, lgf As LOGFONT, tch As hv cdc = CreateDC("DISPLAY", "", "", ByVal 0) ccb = CreateCompatibleBitmap(cdc, 1, 1) DeleteObject SelectObject(cdc, ccb) lgf.lfFaceName = pol.Name & Chr$(0): lgf.lfHeight = -MulDiv(pol.Size, GetDeviceCaps(GetDC(0), 90), 72) lgf.lfItalic = pol.Italic: lgf.lfStrikeOut = pol.Strikethrough: lgf.lfUnderline = pol.Underline lgf.lfWeight = 400 If pol.Bold = True Then lgf.lfWeight = lgf.lfWeight * 2 cfi = CreateFontIndirect(lgf) DeleteObject SelectObject(cdc, cfi) GetTextExtentPoint32 cdc, ch, Len(ch), tch DeleteObject cfi: DeleteDC cdc: DeleteObject ccb dimt = tch End Function
ListBox1.MultiSelect = fmMultiSelectMulti
Private Sub ListBox1_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single) 'enregistrement, à chaque "clic" souris, de la colonne Dim i As Integer For i = UBound(mLeft) To LBound(mLeft) Step -1 If X >= mLeft(i) Then colonne = i: Exit For Next i End Sub Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean) 'EVENEMENT DECLENCHEUR positionnons End Sub Private Sub ListBox1_Enter() 'GESTION DU SCROLL LISTBOX1 If Frame1.Visible Then Frame1.Visible = False End Sub
Private Sub UserForm_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single) Frame1.Visible = False End Sub
Private Sub TextBox1_Change() 'RESTITUTION DES DONNEES DANS LA LISTBOX ListBox1.List(ListBox1.ListIndex, colonne) = TextBox1 End Sub
ByVal ActionX As MSForms.fmScrollAction,
ByVal ActionY As MSForms.fmScrollAction,
ByVal RequestDx As Single,
ByVal RequestDy As Single,
ByVal ActualDx As MSForms.ReturnSingle,
ByVal ActualDy As MSForms.ReturnSingle
Private Sub Frame1_Scroll(ByVal ActionX As MSForms.fmScrollAction, ByVal ActionY As MSForms.fmScrollAction, ByVal RequestDx As Single, ByVal RequestDy As Single, ByVal ActualDx As MSForms.ReturnSingle, ByVal ActualDy As MSForms.ReturnSingle) Select Case ActionX ' ascenseur horizontal Case 1 'clic sur fleche de gauche Debug.Print 1 & "X" Case 2 'clic sur fleche de droite Debug.Print 2 & "X" Case 3 '"grand déplacement" vers la gauche (clic dans la barre) Debug.Print 3 & "X" Case 4 '"grand déplacement" vers la droite Debug.Print 4 & "X" Case 5 'Remise à zéro extrémité gauche Debug.Print 5 & "X" Case 6 'Fin côté droit Debug.Print 6 & "X" End Select Select Case ActionY ' ascenseur vertical Case 1 'clic sur fleche du haut Debug.Print 1 & "Y" Case 2 'clic sur fleche du bas Debug.Print 2 & "Y" Case 3 '"grand déplacement" vers le haut (clic dans la barre) Debug.Print 3 & "Y" Case 4 '"grand déplacement" vers le bas Debug.Print 4 & "Y" Case 5 'Remise à zéro HAUT Debug.Print 5 & "Y" Case 6 'Fin de la liste en BAS Debug.Print 6 & "Y" End Select End Sub
If ListBox1.ColumnWidths = "" Then
Dim zut As Single
zut = ListBox1.Width / ListBox1.ColumnCount
For i = 0 To ListBox1.ColumnCount - 1
ListBox1.ColumnWidths = ListBox1.ColumnWidths & ";" & zut
Next
ListBox1.ColumnWidths = Mid(ListBox1.ColumnWidths, 2)
End If
MsgBox ListBox1.ColumnWidths
ListBox1.Width = 150 ListBox1.ColumnCount = 1 ListBox1.ColumnWidths = "100"
'================================================= Set vba_font = malistbox.Font With vba_font .Bold = malistbox.Font.Bold .Italic = malistbox.Font.Italic End With Haut_Lig = vba_TextHeight("Coucou", vba_font) '=============================================== 'Maintenant on connait la largeur et la hauteur relative au contenu de la listbox 'Affichage ou non des ScrollBars de FRM_hors_tout Dim NbScroll As Byte NbScroll = 0 '0 = fmScrollBarsNone If malistbox.Width >= FRM_hors_tout.Width Then NbScroll = NbScroll + 1 '1 = fmScrollBarsHorizontale If malistbox.ListCount * Haut_Lig / COEFF > FRM_hors_tout.Height Then NbScroll = NbScroll + 2 '2 = fmScrollBarsVerticale FRM_hors_tout.ScrollBars = NbScroll '3 = fmScrollBarsBoth '=============================================== With TextBox1 'Propriétés du TextBox .Height = Haut_Lig + 1 .Move 0, -2 .Font = malistbox.Font .Font.Size = malistbox.Font.Size .Font.Bold = malistbox.Font.Bold .Font.Italic = malistbox.Font.Italic .ForeColor = vbRed End With
'=============================================== 'Maintenant on connait la largeur et la hauteur relative au contenu de la listbox 'Affichage ou non des ScrollBars de FRM_hors_tout NbScroll = 0 '0 = fmScrollBarsNone '1 = fmScrollBarsHorizontale '2 = fmScrollBarsVerticale '3 = fmScrollBarsBoth If malistbox.Width >= FRM_hors_tout.Width Then NbScroll = NbScroll + 1 Else: FRM_hors_tout.Height = FRM_hors_tout.Height - Larg_Scroll End If If malistbox.ListCount * Haut_Lig / COEFF > FRM_hors_tout.Height Then NbScroll = NbScroll + 2 Else: FRM_hors_tout.Width = FRM_hors_tout.Width - Larg_Scroll End If FRM_hors_tout.ScrollBars = NbScroll '===============================================
Modifié par pijaku le 1/07/2015 à 07:42
C'est exactement cela.
Oui, je connais cette source pour l'avoir déjà lue. J'aurais certainement besoin d'un coup de main pour adapter.
Je sais. D'où mon sujet ici même. C'est une tâche très complexe, mais qui vaut certainement le coup. De ce fait, j'ai voulu créer ce sujet pour en faire un "travail" collectif car je ne me sens pas d'y aller tout seul.
C'est aussi pour cela que je pose cette question. Je ne connais pas MSFLEXGRID et vais de ce pas me rencarder.
Je reviendrais après te dire ce qu'il en est.