Like Jules mentioned this thread discussed a lot of times.
All is enough simple, except one - to understand, which size to set for columns, because 1/4 of character "average" width is enough interesting measurement.
That's why below I used fixed width font (Courier) to avoid troubles.
%nx - maximum size of column in chars
dx - space between columns in 1/4 of char
The third column is right alighned. That's why - and total width of all columns.
Code:
#Compile Exe #Register None #Dim All #Include "win32api.inc" %ID_Listbox = 101 %n1 = 3 %n2 = 10 %n3 = 4 %dx = 2 Function PbMain Dim TabArray(1 To 3) As Dword, hDlg As Long Dialog New 0, "Select Test", , , 140, 100, %WS_CAPTION Or %WS_SYSMENU Or %WS_MAXIMIZEBOX To hDlg Control Add ListBox, hDlg, %ID_ListBox, , 10, 10, 120, 90, _ %WS_TABSTOP Or %LBS_USETABSTOPS Or %LBS_DISABLENOSCROLL Or %WS_VSCROLL, %WS_EX_CLIENTEDGE Local lf As LOGFONT, hFont As Long, lResult As Long, rc As RECT GetClientRect GetDlgItem(hDlg, %ID_ListBox), rc lResult = GetStockObject(%ANSI_VAR_FONT) GetObject lResult, SizeOf(lf), ByVal VarPtr(lf) lf.lfFaceName = "Courier New" lf.lfWeight = 0 lf.lfHeight = 0 lf.lfWidth = rc.nRight / 20 hFont = CreateFontIndirect(lf) Control Send hDlg, %ID_LISTBOX, %WM_SETFONT, hFont, 0 TabArray(1) = %n1 * 4 + %dx TabArray(2) = -((%n1 + %n2 + %n3) * 4 + %dx * 3) Dim i As Long, j As Long For i = 1 To 20 j = (i Mod 10) If j = 0 Then j = 10 ListBox Add hDlg, %ID_LISTBOX, Format$(i) + "." + $TAB + _ Left$("Abcdefghijk", j) + $TAB + Format$(i * 50) Next Control Send hdlg, %ID_ListBox, %LB_SETTABSTOPS, 2, VarPtr(TabArray(1)) Control Set Focus hDlg,%ID_ListBox Dialog Show Modal hDlg DeleteObject hFont End Function
E-MAIL: [email protected]
Leave a comment: