bonjour,
ma combobox contient des long chaines, et j'ai un problème lors de la selection d'un item cela m'affiche la fin du chaine.
je voudrais afficher le début. comment faire ?
merci de m'aider
bonjour,
ma combobox contient des long chaines, et j'ai un problème lors de la selection d'un item cela m'affiche la fin du chaine.
je voudrais afficher le début. comment faire ?
merci de m'aider
Bonjour,
Merci pour ces explications précises qui nous aide à comprendre ton environnement, ton problème...
Fais voir ton code d'ajout dans la combobox et là où la récupération foire stp.
c'est claire je pense
problème d'affichage du combox
mes items dans le combox est long , quand je sélection une item le combox affiche la partie dernière de la chaine parce que la taille de ma combox est plus petit que le texte a affiché
donc j'aimerai plutôt affiché la première partie de la chaine
Encore une fois, si tu ne montres pas ton code, je ne pourrais pas t'aider...
Bonjour,
ce lien propose 4 solutions :
Soit modifier DropDownStyle, si c'est possible :
Soit simuler la touche "HOME" :
Code : Sélectionner tout - Visualiser dans une fenêtre à part Me.ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList
Soit user d'un Timer :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3 Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged SendKeys.Send("{HOME}") End Sub
Soit enfin visionner la totalité du texte dans une info-bulle.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7 Private Sub ComboBox1_SelectionChangeCommitted(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectionChangeCommitted Timer1.Start() End Sub Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick Timer1.Stop() ComboBox1.SelectionLength = 0 End Sub
bonjour jalalnet
C'est DrawItem & MeasureItem qui permettent de personnaliser l'affichage des controles type liste savoir :ListBox,ComboBox ,DataGridView,ListView et tutti quanti..........
Dans ton cas il permet de prendre en charge la largeur de l'item à afficher,sa hauteur ,sa font et meme dessiner des "figueres geometriques" pour accompagner l'item chaine affiche.
1er Code Simple pour gerer la largeur de chaine affiche que tu rajoute dans ton form:
2er Code MSDN plus elabore pour montrer ce que permettent DrawItem et MeasureItem pour gerer "customizer" la chaine affiche.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 Public Class Form2 Private listeItems() As String Public Sub New() ' Cet appel est requis par le Concepteur Windows Form. InitializeComponent() ' Ajoutez une initialisation quelconque après l'appel InitializeComponent(). 'Mettre DrawMode.OwnerDrawVariable Me.ComboBox1.DrawMode = DrawMode.OwnerDrawVariable Me.ComboBox1.DropDownWidth = 250 'Mettre ComboBoxStyle.DropDown Me.ComboBox1.DropDownStyle = ComboBoxStyle.DropDown listeItems = New String() {"Les Elephants de la grande Savane formaient une meute immense et effrayante....", "l'enorme et repoussant c r o c o d i l e se glissa dans le marecage.....", "Et le lion bondit sur sa proie ........et dechiqueta l'enorme buffle...et l'avala... "} ComboBox1.DataSource = listeItems Me.Controls.Add(Me.ComboBox1) End Sub ' Comme on a mis DrawMode.OwnerDrawVariable, ' On doit intercepter l'evenement MeasureItem event. ' Cet event handler definit height and width de chaque item ' avant son dessin . Private Sub ComboBox1_MeasureItem(ByVal sender As Object, _ ByVal e As System.Windows.Forms.MeasureItemEventArgs) _ Handles ComboBox1.MeasureItem e.ItemHeight = 30 e.ItemWidth = 260 End Sub ' On doit intercepter aussi l'evenement DrawItem . ' Il sert à definir color, size et font d'un item . Private Sub ComboBox1_DrawItem(ByVal sender As Object, _ ByVal e As System.Windows.Forms.DrawItemEventArgs) _ Handles ComboBox1.DrawItem ' Draw the background of the item. e.DrawBackground() ' Draw each string in the array using font for ComboBox1. e.Graphics.DrawString(listeItems(e.Index), Me.Font, Brushes.Black, _ New RectangleF(e.Bounds.X, e.Bounds.Y, _ e.Bounds.Width, e.Bounds.Height)) ' Draw the focus rectangle if the mouse hovers over an item. e.DrawFocusRectangle() End Sub End Class
A mettre dans un form avec un combox:
bon code................
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 Public Class Form1 Private animals() As String Public Sub New() ' Cet appel est requis par le Concepteur Windows Form. InitializeComponent() ' Ajoutez une initialisation quelconque après l'appel InitializeComponent(). Me.ComboBox1.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable Me.ComboBox1.DropDownWidth = 250 Me.ComboBox1.DropDownStyle = ComboBoxStyle.DropDown animals = New String() {"Elephant", "c r o c o d i l e", "lion"} ComboBox1.DataSource = animals Me.Controls.Add(Me.ComboBox1) End Sub ' If you set the Draw property to DrawMode.OwnerDrawVariable, ' you must handle the MeasureItem event. This event handler ' will set the height and width of each item before it is drawn. Private Sub ComboBox1_MeasureItem(ByVal sender As Object, _ ByVal e As System.Windows.Forms.MeasureItemEventArgs) _ Handles ComboBox1.MeasureItem Select Case e.Index Case 0 e.ItemHeight = 45 Case 1 e.ItemHeight = 20 Case 2 e.ItemHeight = 35 End Select e.ItemWidth = 260 End Sub ' You must handle the DrawItem event for owner-drawn combo boxes. ' This event handler changes the color, size and font of an ' item based on its position in the array. Private Sub ComboBox1_DrawItem(ByVal sender As Object, _ ByVal e As System.Windows.Forms.DrawItemEventArgs) _ Handles ComboBox1.DrawItem Dim size As Single Dim myFont As System.Drawing.Font Dim family As FontFamily Dim animalColor As New System.Drawing.Color Select Case e.Index Case 0 size = 30 animalColor = System.Drawing.Color.Gray family = FontFamily.GenericSansSerif Case 1 size = 10 animalColor = System.Drawing.Color.LawnGreen family = FontFamily.GenericMonospace Case 2 size = 15 animalColor = System.Drawing.Color.Tan family = FontFamily.GenericSansSerif End Select ' Draw the background of the item. e.DrawBackground() ' Create a square filled with the animals color. Vary the size ' of the rectangle based on the length of the animals name. Dim rectangle As Rectangle = New Rectangle(2, e.Bounds.Top + 2, _ e.Bounds.Height, e.Bounds.Height - 4) e.Graphics.FillRectangle(New SolidBrush(animalColor), rectangle) ' Draw each string in the array, using a different size, color, ' and font for each item. myFont = New Font("Times New Roman", size, FontStyle.Bold) e.Graphics.DrawString(animals(e.Index), myFont, System.Drawing.Brushes.Black, _ New RectangleF(e.Bounds.X + rectangle.Width, e.Bounds.Y, _ e.Bounds.Width, e.Bounds.Height)) ' Draw the focus rectangle if the mouse hovers over an item. e.DrawFocusRectangle() End Sub End Class
Partager