檢視原始碼 wxListBox (wx v2.4.3)

列表框用於選取一個或多個字串列表中的項目。

字串會顯示在可捲動的方塊中,選取的字串會以反白顯示。列表框可以是單選(如果選取了項目,則會移除先前的選取)或多選(點擊項目會獨立切換項目的選取狀態)。

列表框元素從零開始編號,雖然元素的最大數量沒有限制,但通常最好使用虛擬控制項,而不需要一次新增所有項目,例如 wxDataViewCtrl(在 wx 中未實作)或搭配 wxLC_VIRTUAL 樣式的 wxListCtrl,一旦需要顯示超過數百個項目時,因為此控制項在效能或使用者介面方面,對於大量項目都沒有優化。

請注意,列表框不支援 TAB 以外的控制字元。

樣式

此類別支援以下樣式

  • wxLB_SINGLE:單選列表。

  • wxLB_MULTIPLE:多選列表:使用者可以切換多個項目的選取狀態。這在 wxGTK2 連接埠中與 wxLB_EXTENDED 相同。

  • wxLB_EXTENDED:延伸選取列表:使用者可以使用 SHIFTCTRL 鍵以及游標移動鍵或滑鼠來延伸選取範圍。

  • wxLB_HSCROLL:如果內容太寬,則建立水平捲軸(僅限 Windows)。

  • wxLB_ALWAYS_SB:永遠顯示垂直捲軸。

  • wxLB_NEEDED_SB:僅在需要時建立垂直捲軸。

  • wxLB_NO_SB:不建立垂直捲軸(僅限 wxMSW 和 wxGTK)。

  • wxLB_SORT:列表框內容會按字母順序排序。請注意,wxLB_SINGLEwxLB_MULTIPLEwxLB_EXTENDED 樣式是互斥的,您最多只能指定其中一個(預設為單選)。另請參閱 overview_windowstyles。

請參閱

此類別繼承自,且可以使用以下類別的功能:

wxWidgets 文件:wxListBox

事件

此類別發出的事件類型

摘要

函式

取消選取列表框中的項目。

銷毀物件

填入一個整數陣列,其中包含目前所選取項目的位置。

傳回位於 point 的項目,如果 point 沒有項目,則傳回 wxNOT_FOUND

這是一個為了方便而提供的多載成員函式。它與上述函式唯一的不同之處在於它接受的引數。

在指定的位置之前插入給定數量的字串。

判斷是否已選取項目。

預設建構函式。

建構函式,建立並顯示列表框。

將目前的控制項內容替換為給定的項目。

設定指定的項目為第一個可見項目。

類型

-type wxListBox() :: wx:wx_object().

函式

連結到此函式

create(This, Parent, Id, Pos, Size, Choices)

檢視原始碼
-spec create(This, Parent, Id, Pos, Size, Choices) -> boolean()
                when
                    This :: wxListBox(),
                    Parent :: wxWindow:wxWindow(),
                    Id :: integer(),
                    Pos :: {X :: integer(), Y :: integer()},
                    Size :: {W :: integer(), H :: integer()},
                    Choices :: [unicode:chardata()].

等同於 create(This, Parent, Id, Pos, Size, Choices, [])

-spec create(This, Parent, Id, Pos, Size, Choices, [Option]) -> boolean()
                when
                    This :: wxListBox(),
                    Parent :: wxWindow:wxWindow(),
                    Id :: integer(),
                    Pos :: {X :: integer(), Y :: integer()},
                    Size :: {W :: integer(), H :: integer()},
                    Choices :: [unicode:chardata()],
                    Option :: {style, integer()} | {validator, wx:wx_object()}.
-spec deselect(This, N) -> ok when This :: wxListBox(), N :: integer().

取消選取列表框中的項目。

備註:這僅適用於多選列表框。

-spec destroy(This :: wxListBox()) -> ok.

銷毀物件

-spec getSelections(This) -> Result
                       when Result :: {Res :: integer(), Selections :: [integer()]}, This :: wxListBox().

填入一個整數陣列,其中包含目前所選取項目的位置。

傳回值:選取的數量。

備註:請在多選列表框中使用。

請參閱

-spec hitTest(This, Point) -> integer()
                 when This :: wxListBox(), Point :: {X :: integer(), Y :: integer()}.

傳回位於 point 的項目,如果 point 沒有項目,則傳回 wxNOT_FOUND

目前已在 wxMSW、wxMac 和 wxGTK2 連接埠中實作。

傳回值:位於點的項目,如果未實作或項目不存在,則傳回 wxNOT_FOUND。

自:2.7.0

-spec hitTest(This, X, Y) -> integer() when This :: wxListBox(), X :: integer(), Y :: integer().

這是一個為了方便而提供的多載成員函式。它與上述函式唯一的不同之處在於它接受的引數。

連結到此函式

insertItems(This, Items, Pos)

檢視原始碼
-spec insertItems(This, Items, Pos) -> ok
                     when This :: wxListBox(), Items :: [unicode:chardata()], Pos :: integer().

在指定的位置之前插入給定數量的字串。

-spec isSelected(This, N) -> boolean() when This :: wxListBox(), N :: integer().

判斷是否已選取項目。

傳回值:如果已選取給定項目,則為 true,否則為 false。

-spec new() -> wxListBox().

預設建構函式。

-spec new(Parent, Id) -> wxListBox() when Parent :: wxWindow:wxWindow(), Id :: integer().

等同於 new(Parent, Id, [])

-spec new(Parent, Id, [Option]) -> wxListBox()
             when
                 Parent :: wxWindow:wxWindow(),
                 Id :: integer(),
                 Option ::
                     {pos, {X :: integer(), Y :: integer()}} |
                     {size, {W :: integer(), H :: integer()}} |
                     {choices, [unicode:chardata()]} |
                     {style, integer()} |
                     {validator, wx:wx_object()}.

建構函式,建立並顯示列表框。

請參閱另一個 new/3 建構函式;唯一的區別在於這個多載接受的是 wxArrayString(在 wx 中未實作),而不是指向 wxString 陣列的指標(在 wx 中未實作)。

-spec set(This, Items) -> ok when This :: wxListBox(), Items :: [unicode:chardata()].

將目前的控制項內容替換為給定的項目。

請注意,如果您需要新增大量項目,呼叫這個方法通常比逐一附加它們快得多。

-spec setFirstItem(This, N) -> ok when This :: wxListBox(), N :: integer();
                  (This, String) -> ok when This :: wxListBox(), String :: unicode:chardata().

設定指定的項目為第一個可見項目。