Bonjour à tous,
mon programme récupère des datas via une carte d'acquisition. J'ai mis en place un événement qui s'active dès la réception d'une des datas. Les datas sont envoyées très rapidement (de l'ordre de la ms). J'affiche sur ma listbox les différentes datas qui sont récupérées. Chaque data possède un identifiant unique que je place dans une ligne précise de ma listbox. Je met à jour la ligne de ma listbox concernée lors de la réception d'une data
Voici mon problème :
Lorsqu'il y a qu'une data qui est reçu => pas de problème, ma listbox est correctement mise à jour sans freeze ni clignotement.
En revanche, plus je reçoit de datas, plus le contenu de ma listbox freeze et lorsque je reçois 12 datas, je ne vois pratiquement plus rien.
J'ai tenté de faire un doublebuffered sur ma listbox mais cela n'a rien changé.
J'ai tenté le code ci-dessous. Résultat : ça ne freeze plus en revanche le temps de réponse de l'affichage est beaucoup trop long et par conséquent, le traitement que je fais derrière ne suit plus.
Auriez-vous des idées pour palier au problème ?
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 public class DoubleBufferedListBox : System.Windows.Forms.ListBox { public DoubleBufferedListBox() { this.SetStyle( ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.UserPaint, true); this.DrawMode = DrawMode.OwnerDrawFixed; } protected override void OnDrawItem(DrawItemEventArgs e) { if (this.Items.Count > 0) { e.DrawBackground(); e.Graphics.DrawString(this.Items[e.Index].ToString(), e.Font, new SolidBrush(this.ForeColor), new PointF(e.Bounds.X, e.Bounds.Y)); } base.OnDrawItem(e); } protected override void OnPaint(PaintEventArgs e) { Region iRegion = new Region(e.ClipRectangle); e.Graphics.FillRegion(new SolidBrush(this.BackColor), iRegion); if (this.Items.Count > 0) { for (int i = 0; i < this.Items.Count; ++i) { System.Drawing.Rectangle irect = this.GetItemRectangle(i); if (e.ClipRectangle.IntersectsWith(irect)) { if ((this.SelectionMode == SelectionMode.One && this.SelectedIndex == i) || (this.SelectionMode == SelectionMode.MultiSimple && this.SelectedIndices.Contains(i)) || (this.SelectionMode == SelectionMode.MultiExtended && this.SelectedIndices.Contains(i))) { OnDrawItem(new DrawItemEventArgs(e.Graphics, this.Font, irect, i, DrawItemState.Selected, this.ForeColor, this.BackColor)); } else { OnDrawItem(new DrawItemEventArgs(e.Graphics, this.Font, irect, i, DrawItemState.Default, this.ForeColor, this.BackColor)); } iRegion.Complement(irect); } } } base.OnPaint(e); } }
D'avance, je vous en remercie.
Voici le code permettant la mise à jour de ma listebox :
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 public void Affichage(AcquisitionTrameEventArgs Acq) { int index = 0; switch (Monitoring_type) { case "Monitoring_statique": if (checkList(Acq.myEventAcquisition.Id)) { int i; for (i = 0; i < Liste_ID.Count; i++) { if (Liste_ID[i] == Acq.myEventAcquisition.Id) { index = Liste_ID.IndexOf(Acq.myEventAcquisition.Id); break; } } listBox_TrameCAN.Items.RemoveAt(index); listBox_TrameCAN.BeginUpdate(); listBox_TrameCAN.Items.Insert(index, index + "\t\t" + Acq.myEventAcquisition.Time + "\t\t" + Acq.myEventAcquisition.Id.ToString("X") + "\t\t" + Acq.myEventAcquisition.Data[0].ToString("X") + " " + Acq.myEventAcquisition.Data[1].ToString("X") + " " + Acq.myEventAcquisition.Data[2].ToString("X") + " " + Acq.myEventAcquisition.Data[3].ToString("X") + " " + Acq.myEventAcquisition.Data[4].ToString("X") + " " + Acq.myEventAcquisition.Data[5].ToString("X") + " " + Acq.myEventAcquisition.Data[6].ToString("X") + " " + Acq.myEventAcquisition.Data[7].ToString("X")); listBox_TrameCAN.EndUpdate(); } //On ajoute l'identifiant à la liste else { listBox_TrameCAN.BeginUpdate(); listBox_TrameCAN.Items.Insert(Liste_ID.Count, Acq.myEventAcquisition.Time + "\t\t" + Acq.myEventAcquisition.Id.ToString("X") + "\t\t" + Acq.myEventAcquisition.Data[0].ToString("X") + " " + Acq.myEventAcquisition.Data[1].ToString("X") + " " + Acq.myEventAcquisition.Data[2].ToString("X") + " " + Acq.myEventAcquisition.Data[3].ToString("X") + " " + Acq.myEventAcquisition.Data[4].ToString("X") + " " + Acq.myEventAcquisition.Data[5].ToString("X") + " " + Acq.myEventAcquisition.Data[6].ToString("X") + " " + Acq.myEventAcquisition.Data[7].ToString("X")); listBox_TrameCAN.EndUpdate(); Liste_ID.Add(Acq.myEventAcquisition.Id); Liste_ID.Sort(); for (int i = 0; i < Liste_ID.Count; i++) { if (Liste_ID.ElementAt(i) == Acq.myEventAcquisition.Id) ListReceptionTrameMemorisee.Insert(i, Acq.myEventAcquisition); } } break; default: MessageBox.Show("Pas codé pour l'instant"); break; } }
Partager