Bonjour ,
ma question est tres simple, je veux comme même utiliser un comboBox
sans que la flche apparait.
Je vous remercie d'avance
Version imprimable
Bonjour ,
ma question est tres simple, je veux comme même utiliser un comboBox
sans que la flche apparait.
Je vous remercie d'avance
J'ai pensé sur le moment à utiliser un textbox avec un Handled sur le keypress et un autocomplete contenant ta liste... sauf que j'ai pas trouvé de moyen de forcer l'affichage de la liste d'autocomplete sur click de la souris...
bonjour marocdivers
Si tu supprimes ladite fleche -et que tu as bien pris soin de la regarder franchement les yeux dans les yeux - tu constateras qu'elle est dessine en fait à l'interieur d'un petit rectangle qui represente helas une zone clickable qui signale au controle qu'on a clique...
Du coup on ne pourras plus signaler au controle l'etat actuel(active,desactive)Cette fleche dessine dans le petit rectangle à droite est un veritable bouton couple au textbox...
Par quoi vas-tu le substituer?.....cliquer dans le textbox?.
Helas les click du textbox sont reserves au textbox pour les selectedindex et tutti quanti...
En resume si on fait cela on va reinventer la roue c.à.d finir dans une "nouvelle version" du listbox car un listbox visuellement n'est qu'un combobox sans la fleche et dont dropdowned en permanence.............
bon code................
rebonjour marocdivers
Voici comment on peut personnaliser le combobox à l'aide de l' API VisualStyles ................
L'extrait de code qui montre qu'on ne peut pas supprimer "la fleche" et il faut comprendre egalement que les styles visuels doivent etre actives:Citation:
Extrait MSDN Doc:
Cela est utile si vous dessinez un contrôle personnalisé qui doit avoir l'apparence du style visuel actuel. Pour dessiner une zone de liste déroulante, utilisez la méthode DrawTextBox pour dessiner la zone de texte et la méthode DrawDropDownButton pour dessiner la flèche de déroulement.
Si tu supprimes arrowRectangleil ne restera plus qu'un pauvre textbox inefficace ..................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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142 using System; using System.Drawing; using System.Windows.Forms; using System.Windows.Forms.VisualStyles; namespace ComboBoxRendererSample { class Form1 : Form { public Form1() : base() { this.Size = new Size(300, 300); CustomComboBox ComboBox1 = new CustomComboBox(); Controls.Add(ComboBox1); } [STAThread] static void Main() { // The call to EnableVisualStyles below does not affect // whether ComboBoxRenderer.IsSupported is true; as long as visual // styles are enabled by the operating system, IsSupported is true. Application.EnableVisualStyles(); Application.Run(new Form1()); } } public class CustomComboBox : Control { private Size arrowSize; private Rectangle arrowRectangle; private Rectangle topTextBoxRectangle; private Rectangle bottomTextBoxRectangle; private ComboBoxState textBoxState = ComboBoxState.Normal; private ComboBoxState arrowState = ComboBoxState.Normal; private String bottomText = "Using ComboBoxRenderer"; private bool isActivated = false; private const int minHeight = 38; private const int minWidth = 40; public CustomComboBox() : base() { this.Location = new Point(10, 10); this.Size = new Size(140, 38); this.Font = SystemFonts.IconTitleFont; this.Text = "Click the button"; // Initialize the rectangles to look like the standard combo // box control. arrowSize = new Size(18, 20); arrowRectangle = new Rectangle(ClientRectangle.X + ClientRectangle.Width - arrowSize.Width - 1, ClientRectangle.Y + 1, arrowSize.Width, arrowSize.Height); topTextBoxRectangle = new Rectangle(ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width, arrowSize.Height + 2); bottomTextBoxRectangle = new Rectangle(ClientRectangle.X, ClientRectangle.Y + topTextBoxRectangle.Height, ClientRectangle.Width, topTextBoxRectangle.Height - 6); } // Draw the combo box in the current state. protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); if (!ComboBoxRenderer.IsSupported) { this.Parent.Text = "Visual Styles Disabled"; return; } this.Parent.Text = "CustomComboBox Enabled"; // Always draw the main text box and drop down arrow in their // current states ComboBoxRenderer.DrawTextBox(e.Graphics, topTextBoxRectangle, this.Text, this.Font, textBoxState); ComboBoxRenderer.DrawDropDownButton(e.Graphics, arrowRectangle, arrowState); // Only draw the bottom text box if the arrow has been clicked if (isActivated) { ComboBoxRenderer.DrawTextBox(e.Graphics, bottomTextBoxRectangle, bottomText, this.Font, textBoxState); } } protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); // Check whether the user clicked the arrow. if (arrowRectangle.Contains(e.Location) && ComboBoxRenderer.IsSupported) { // Draw the arrow in the pressed state. arrowState = ComboBoxState.Pressed; // The user has activated the combo box. if (!isActivated) { this.Text = "Clicked!"; textBoxState = ComboBoxState.Pressed; isActivated = true; } // The user has deactivated the combo box. else { this.Text = "Click here"; textBoxState = ComboBoxState.Normal; isActivated = false; } // Redraw the control. Invalidate(); } } protected override void OnMouseUp(MouseEventArgs e) { base.OnMouseUp(e); if (arrowRectangle.Contains(e.Location) && ComboBoxRenderer.IsSupported) { arrowState = ComboBoxState.Normal; Invalidate(); } } } }
bon code...............
bon code.................
tu te trompes mr mebrouki, pourquoi?
une listeBox n'est accessible qu'on lecture. tu ne peux pas te positionner sur le textbox pour erire.
et la flèche mr mebrouki peut etre remplacer par un evenement du clavier
bonjour maroccodivers
Eh bien,puisque tu peux la remplacer par un evenement clavier ,tu preux carrement supprimer la combobox tant que tu y est et ne plus poser de question................
Quant au listbox et combbox je vois que pour toi il y a une difference gigantestque entre un textbox en lecture seule et un textbox lecture-ecriture....
bonne soiree
tu essaye de répondre sans bien comprendre la question ni le besoin,
Monsieur Mabrouki, un textBox ne te permet pas de balyer une collection,
tandis que comme tu le sais un comboBox te permet de balayer une liste de collection...
Autrement, c'est le client qui a demandé d'enlever la fleche !
Autre part la réponse je l'ai deja trouvé , et pour les gens qui la cherche :
Pour enlever la fleche du comboBox et garder les événements de ce comboBox
il faut affecter a la propriété DrowDownStyle la valeur Simple.