Jump to content
Sign in to follow this  
Chamuanza

[Resolvido] Alterar Alguns Items de Combobox p/ Negrito

Recommended Posts

Chamuanza

Um bem Aja a todos

Tenho uma Combobox preenchida com uma colecção de items.

É possivel apresentar alguns desses items a negrito?

Um obrigado desde já

Share this post


Link to post
Share on other sites
nelsonr

Tive a fazer uns testes, podes tentar adaptar a partir daqui:

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ComboBox1.DrawMode = DrawMode.OwnerDrawVariable
Dim lista As String() = New String() {"Portugal", "a", "Programar"}
ComboBox1.DataSource = lista
End Sub

'
Private Sub ComboBox1_DrawItem(sender As Object, e As DrawItemEventArgs) Handles ComboBox1.DrawItem
Dim font As Font = ComboBox1.Font

'
e.DrawBackground()

' Ao desenhar o item na posição 1 ("a"), altera a fonte para usar o Bold
If e.Index = 1 Then
	font = New Font(ComboBox1.Font.FontFamily.Name, ComboBox1.Font.Size, FontStyle.Bold)
End If

'
e.Graphics.DrawString( _
		ComboBox1.Items(e.Index).ToString(), _
		font, _
		System.Drawing.Brushes.Black, _
		New RectangleF(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height) _
		)

'
e.DrawFocusRectangle()
End Sub

'
Private Sub ComboBox1_MeasureItem(sender As Object, e As MeasureItemEventArgs) Handles ComboBox1.MeasureItem
e.ItemHeight = 17
End Sub

Share this post


Link to post
Share on other sites
Chamuanza

Oi nelsonr

Obrigado pela ajuda, erra isto mesmo que pretendia, fazer sobressair alguns items da lista

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.