Discussion Locked

ComboBox in Visual Basic

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
How can i display different fonts in the combo box with their font style displaying accordingly at each index when the user click the ComboBox at runtime ?

5 replies

by amanabala

Hi,
This code assumes a form (form1) with a combo box(combo1) and a text box (text1).
Whenever the text in combo box changes, the font changes and the new text is displayed in the text box.

If you need further assitance, please let me know

-Ravi

'Form General Code block

Dim fonts(5) As String

Private Sub Combo1_Click()
Dim i As Integer
i = Combo1.ListIndex
Text1.Text = fonts(i)
Combo1.FontName = fonts(i)
End Sub

Private Sub Form_Load()
fonts(0) = "MS Sans Serif"
fonts(1) = "Arial"
fonts(2) = "Tahoma"
fonts(3) = "Verdana"
fonts(4) = "Times New Roman"
End Sub

by shariqsaad

My problem is that i dont want any text fields just one combo box that's it.
The combo box entries should be displayed in the respected font types.
i anyone can help me than please do.

by amanabala

Dear Shariqsaad,

The textbox in the example I sent you was to display the result of the code, it was not necessary: You can remove the text box and the code to write to the text box. I can send you the code by email if you would like.
regards,
Ravi

by shariqsaad

Dear Ravi,
When I change one font all the fonts in the combo box also change their fontstyle which i dont want to happen.
i want every font listed in the combo box to appear in its own fontstyle when i open the combo box.

This discussion is closed to new replies.