Bonjour,
j'ai un combobox contient les items suivant:"Ministere","Wali","Architecte",..
je veux mettre en gras l'item ayant le texte "Ministere" et je sais pas comment??
Merci de me répondre.
cordialement,
Ahbari
Version imprimable
Bonjour,
j'ai un combobox contient les items suivant:"Ministere","Wali","Architecte",..
je veux mettre en gras l'item ayant le texte "Ministere" et je sais pas comment??
Merci de me répondre.
cordialement,
Ahbari
Bonjour,
Les propriétés ForeColor, Font, ... appartiennent à la l'objet Combobox,
et non à Items
Tu ne peux donc pas personnaliser 1 items en particulier.
Fin de la discution. :aie:
Alors c'est impossible de personnaliser un item dans le combobox.:cry:
Vous n'avez pas aucune solution pour résoudre ce problème?Mais...:cry::cry:
Oo rien d'impossible, mais c'est du boulot je pense.
Certains se sont amusés à faire une extension de la Combobox d'origine.
regarde ici: ;)
http://www.codeproject.com/KB/combob...oxControl.aspx
bonkour ahbari
El ahbar ....
Qui as dit que c'est impossible.
Probablement que hunteshiva a oublie je pense les event DrawItem et MeasureItem du ComboBox (et valable piur les cousins listbox ,listview & checkbox....)...
Voici le code pour personnaliser le font,son size et sa couleur.....
Ne pas oublier de mettre pour le ComboBox concerne la prop DrawMode = DrawMode.OwnerDrawVariable qui veut dire vous prener en charge le desin des items.....
code exemple simple avec un bouton et un combo qui changent le font,la couleur et le size du font du ministre et de son compere le wali.... :
bon code...............Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90 Public Class Form1 Public Sub New() ' This call is required by the designer. InitializeComponent() ' Add any initialization after the InitializeComponent() call. Me.ComboBox1.DrawMode = DrawMode.OwnerDrawVariable Me.ComboBox1.DropDownWidth = 250 Me.ComboBox1.DropDownStyle = ComboBoxStyle.DropDown End Sub Private Sub btnFillCombo_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFillCombo.Click For i As Integer = 0 To 9 ComboBox1.Items.Add("Ministere" & (i + 1).ToString) ComboBox1.Items.Add("Wali" & (i + 1).ToString) ComboBox1.Items.Add("Architecte" & (i + 1).ToString) Next End Sub 'il est necessaire de mesurer '- hauteur de l'item '- largeur de l'item '-suivant le font utilise Private Sub ComboBox1_MeasureItem(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MeasureItemEventArgs) Handles ComboBox1.MeasureItem 'variable font pour chaque item. Dim FontMinistere As Font = New Font("Arial Bold", 16, FontStyle.Bold) Dim FontWali As Font = New Font("Arial Bold", 16, FontStyle.Bold) Dim FontCombo As Font = Me.ComboBox1.Font 'recupere l'item courant Dim stringItem As String = ComboBox1.Items(e.Index) If stringItem.Contains("Ministere") Then e.ItemHeight = FontMinistere.GetHeight(e.Graphics) ElseIf stringItem.Contains("Wali") Then e.ItemHeight = FontWali.GetHeight(e.Graphics) Else e.ItemHeight = FontCombo.GetHeight(e.Graphics) End If 'largeur de l'item e.ItemWidth = 260 End Sub ' This event handler changes the color, size and font of an ' item based on the value containing a particular string. Private Sub ComboBox1_DrawItem(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles ComboBox1.DrawItem ' Draw the background of the item. e.DrawBackground() 'un variable font pour personnaliser le font de chaque item. Dim myFont As Font Dim myBrush As Brush 'recupere l'item courant Dim stringItem As String = ComboBox1.Items(e.Index) If stringItem.Contains("Ministere") Then ' Draw each string using a different size, color, ' and font for each item. myFont = New Font("Times New Roman", 18, FontStyle.Bold) myBrush = Brushes.Red e.Graphics.DrawString(stringItem, myFont, myBrush, _ New RectangleF(e.Bounds.X, e.Bounds.Y, _ e.Bounds.Width, e.Bounds.Height)) ElseIf stringItem.Contains("Wali") Then myFont = New Font("Arial Bold", 16, FontStyle.Bold) myBrush = Brushes.GreenYellow e.Graphics.DrawString(stringItem, myFont, myBrush, _ New RectangleF(e.Bounds.X, e.Bounds.Y, _ e.Bounds.Width, e.Bounds.Height)) Else 'par defaut myFont = Me.ComboBox1.Font myBrush = New SolidBrush(Me.ComboBox1.ForeColor) e.Graphics.DrawString(stringItem, Me.Font, myBrush, _ New RectangleF(e.Bounds.X, e.Bounds.Y, _ e.Bounds.Width, e.Bounds.Height)) End If ' Draw the focus rectangle if the mouse hovers over an item. e.DrawFocusRectangle() End Sub End Class
Merci Mabrouki votre code est tellement utile
:ccool::ccool::ccool: