4
I am creating an important effect for the presentation of a Combobox in particular.
This Combobox is originally produced centralized, and when opening your list I make the text left-aligned so that items in your list are displayed left-aligned, but the idea is that the text of the Combobox box remains centralized. Like it is not possible to do this only with own Combobox, I found a way:
A "Label" with the same text of Combobox and also centralized has the approximate size of this Combobox and becomes visible on it when Combobox is selected, and this is done through the "Enter".
Thus, the user see the centered text in Combobox since the label hides the original text that is aligned to the left by the "Enter" event, and the list is presented automatically through the "Dropdown" left-aligned. So far, so perfect!
I prepared the "Click" Label event in case the user "click" on it instead of selecting an item, then the Label "would be removed" (becoming invisible) and the list would be closed, however, in this case the list is NOT closed, but the label is removed, then need to "click" on the Combobox to close the list (at this time the Combobox text is again centralized).
If there was a control over the "closing of the list", when the label is removed in the first "click" the list would be closed, but in the searches I found nothing that could use or solve the problem.
There is some form of control on closing the Combobox list in VBA, or another way to create this effect?
The code for verification is this:
Private Sub UserForm_activate()
ComboBox1.TextAlign = fmTextAlignCenter
ComboBox1.AddItem "Primeiro"
ComboBox1.AddItem "Segundo"
ComboBox1.AddItem "Terceiro"
ComboBox1.ListIndex = 0
Label1.Left = ComboBox1.Left + 2
Label1.Width = ComboBox1.Width - 4
Label1.Top = ComboBox1.Top + 2
Label1.Height = ComboBox1.Height - 2
Label1.TextAlign = fmTextAlignCenter
Label1.BorderStyle = fmBorderStyleNone
Label1.ZOrder 0
Label1.Visible = False
TextBox1.SetFocus
End Sub
Private Sub ComboBox1_enter()
ComboBox1.TextAlign = fmTextAlignLeft
Label1 = ComboBox1.Text
Label1.Visible = True
ComboBox1.DropDown
End Sub
Private Sub Label1_Click()
ComboBox1.TextAlign = fmTextAlignCenter
Label1.Visible = False
End Sub
Have you tried using <code> Private Sub Combobox_change() </code>? This might work.
– Evert
Hi Evert, Change is not triggered because there is no selection of an item in the list.
– Leo
Got @Leo... complicated... has how to send the spreadsheet to take a look or the code you are using?
– Evert
I think if you refresh the form maybe? Recording and searching for information already entered...
– Evert
There was a mistake and I changed parts of the text, because in fact what happens is the opposite of what I described, the label is removed, but the list remains open.
– Leo
I think I understand what you want... I think the sequence of the codes needs to be adjusted. One minute I will assemble here to test.
– Evert
I changed the code too, I had the alignments reversed.
– Leo