2017-07-27 119 views
2

這是我在表單中創建的列表框。列表框添加項目間距

enter image description here

我需要的是通過增加項目的間距如下修改ListBox中的項目清單。 enter image description here

我搜索通過網絡和應用我找到了解決方案,在我的代碼,但沒有奏效。 這是我添加項目到列表框的代碼。

With mobjApplication 
    List1.AddItem vbCrLf + " " + .GetUIString("frmSettings.ServerConnections") + vbCrLf + "", 0 
    List1.AddItem " " + .GetUIString("frmSettings.WorkflowOptions") & "", 1 
    List1.AddItem " " + .GetUIString("frmSettings.Appearance") & "", 2 
    List1.AddItem " " + .GetUIString("frmSettings.FileLocations") & "", 3 
End with 

請有人幫我這個。

回答

5

也許:

Option Explicit 

Private Const LB_SETITEMHEIGHT As Long = &H1A0& 

Private Declare Function SendMessage Lib "user32" Alias "SendMessageW" (_ 
    ByVal hWnd As Long, _ 
    ByVal wMsg As Long, _ 
    ByVal wParam As Long, _ 
    ByVal lParam As Long) As Long 

Private Sub Form_Load() 
    Const LIST_ITEM_HEIGHT As Long = 40 'Pixels. 

    With List1 
     .Font.Name = "Segoe UI" 
     .Font.Size = 14 
     SendMessage .hWnd, LB_SETITEMHEIGHT, 0, LIST_ITEM_HEIGHT 
     .AddItem "Server Connections" 
     .AddItem "Workflow Options" 
     .AddItem "Appearance" 
     .AddItem "File Locations" 
    End With 
End Sub 
+0

它工作得很好。謝謝 –

+0

請告訴我應該在代碼中添加什麼樣的改進才能使列表中的文本添加到中間。 –

+1

可能只適用於所有者繪製的ListBox。 – Bob77

-2

您不能在ListBox中添加'項目空間'。圖像中的項目之間沒有空格(Word選項)。 爲了模仿以下(Word選項)的列表中,嘗試設置您的列表框:

Private Sub Form_Load() 
    List1.Font.Name = "Segoe UI" 
    List1.Font.Size = 20 
End Sub 

enter image description here

0

我修改了代碼,每@ Bob77的答案,但我無法將列表框項目垂直對齊到項目空間的中心。

enter image description here

按鮑勃,我們需要創建所有者繪製列表框來實現它。 所以我試圖找到另一個控件而不是listBox,並嘗試使用listView和Treeview。根據@Giorgio的回答,我嘗試了「Segoe UI」。 Treeview用這種字體給出了最多的項目間距,並且它在一定程度上滿足了我的期望。

現在我的用戶界面如下。