Bonjour,
J'ai un combo, avec 3 evenements persos (Enter, DropDown, DrawItem). Lorsque je clic à coté, il conserve le focus !??
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 comboBoxLibelleRestoria.Enter += new EventHandler(comboBoxLibelleRestoria_Enter); comboBoxLibelleRestoria.DrawMode = DrawMode.OwnerDrawFixed; comboBoxLibelleRestoria.DrawItem += new DrawItemEventHandler(comboBoxLibelleRestoria_DrawItem); comboBoxLibelleRestoria.DropDown += new EventHandler(comboBoxLibelleRestoria_DropDown);
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10 void comboBoxLibelleRestoria_Enter(object sender, EventArgs e) { if (comboBoxLibelleRestoria.Items.Count == 0) { var item = Util.ListArticles.Values.FirstOrDefault(art => art.ELEMENT_REPAS == this.labelElement.Text && art.LIBELLE_RESTORIA == comboBoxLibelleRestoria.Text); PopulateComboboxLibelleRestoria(this.labelElement.Text); comboBoxLibelleRestoria.SelectedItem = item; } }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 void comboBoxLibelleRestoria_DrawItem(object sender, DrawItemEventArgs e) { Article item = (Article)((ComboBox)sender).Items[e.Index]; var lib = getArticleLibelleRecherche(item); e.DrawBackground(); using (SolidBrush br = new SolidBrush(e.ForeColor)) { e.Graphics.DrawString(lib, e.Font, br, e.Bounds); } e.DrawFocusRectangle(); }Quelqu'un aurait une idée ? un contournement ?
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 void comboBoxLibelleRestoria_DropDown(object sender, EventArgs e) { ComboBox senderComboBox = (ComboBox)sender; int width = senderComboBox.DropDownWidth; Graphics g = senderComboBox.CreateGraphics(); Font font = senderComboBox.Font; int vertScrollBarWidth = (senderComboBox.Items.Count > senderComboBox.MaxDropDownItems) ? SystemInformation.VerticalScrollBarWidth : 0; int newWidth; foreach (Article art in ((ComboBox)sender).Items) { newWidth = (int)g.MeasureString(getArticleLibelleRecherche(art), font).Width + vertScrollBarWidth; if (width < newWidth) { width = newWidth; } } senderComboBox.DropDownWidth = width; }
Partager