Controlar o comportamento de estilo e seleção de uma caixa de lista
O exemplo a seguir usa as propriedades ListStyle e MultiSelect para controlar a aparência de uma ListBox. O usuário escolhe um valor para ListStyle usando o ToggleButton e escolhe um OptionButton para um dos valores MultiSelect . A aparência da ListBox mudará de acordo, assim como o comportamento de seleção na ListBox.
To use this example, copy this sample code to the Script Editor of a form. To run the code you need to open the form so the Open event will activate. Make sure that the form contains:
A ListBox named ListBox1.
Um rótulo chamado Label1.
Três controles OptionButton denominados OptionButton1 a OptionButton3.
Um ToggleButton denominado ToggleButton1.
Sub Item_Open()
Set ListBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ListBox1")
Set Label1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("Label1")
Set OptionButton1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("OptionButton1")
Set OptionButton2 = Item.GetInspector.ModifiedFormPages("P.2").Controls("OptionButton2")
Set OptionButton3 = Item.GetInspector.ModifiedFormPages("P.2").Controls("OptionButton3")
Set ToggleButton1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ToggleButton1")
For i = 1 To 8
ListBox1.AddItem "Choice" & (ListBox1.ListCount + 1)
Next
Label1.Caption = "MultiSelect Choices"
Label1.AutoSize = True
ListBox1.MultiSelect = 0 '0=fmMultiSelectSingle
OptionButton1.Caption = "Single entry"
OptionButton1.Value = True
OptionButton2.Caption = "Multiple entries"
OptionButton3.Caption = "Extended entries"
ToggleButton1.Caption = "ListStyle - Plain"
ToggleButton1.Value = True
ToggleButton1.Width = 90
ToggleButton1.Height = 30
End Sub
Sub OptionButton1_Click()
Set ListBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ListBox1")
ListBox1.MultiSelect = 0 '0=fmMultiSelectSingle
End Sub
Sub OptionButton2_Click()
Set ListBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ListBox1")
ListBox1.MultiSelect = 1 '1=fmMultiSelectMulti
End Sub
Sub OptionButton3_Click()
Set ListBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ListBox1")
ListBox1.MultiSelect = 2 '2=fmMultiSelectExtended
End Sub
Sub ToggleButton1_Click()
Set ToggleButton1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ToggleButton1")
Set ListBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ListBox1")
If ToggleButton1.Value = True Then
ToggleButton1.Caption = "Plain ListStyle"
ListBox1.ListStyle = 0 '0=fmListStylePlain
Else
ToggleButton1.Caption = "OptionButton or CheckBox"
ListBox1.ListStyle = 1 '1=fmListStyleOption
End If
End Sub
Suporte e comentários
Tem dúvidas ou quer enviar comentários sobre o VBA para Office ou sobre esta documentação? Confira Suporte e comentários sobre o VBA para Office a fim de obter orientação sobre as maneiras pelas quais você pode receber suporte e fornecer comentários.
Comentários
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Enviar e exibir comentários de