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
| public class AnalyseListBox : System.Windows.Forms.ListBox
{
private ArrayList m_aValeurAnalyse = new ArrayList();
private SolidBrush m_SBwrited= new SolidBrush(Color.Green);
private SolidBrush m_SBunwrited = new SolidBrush(Color.Red);
private SolidBrush m_SBselectedItem = new SolidBrush(Color.White);
public AnalyseListBox()
{
this.DrawMode = DrawMode.OwnerDrawVariable;
}
public void Clear()
{
m_aValeurAnalyse.Clear();
this.Items.Clear();
}
public void AddItem(String NomAnalyse)
{
m_aValeurAnalyse.Add((double)0);
this.Items.Add(NomAnalyse);
}
public void SetWritedColor(Color Couleur)
{
m_SBwrited = null;
m_SBwrited = new SolidBrush(Couleur);
}
public void SetUnwritedColor(Color Couleur)
{
m_SBunwrited = null;
m_SBunwrited = new SolidBrush(Couleur);
}
public void SetItemValue(int ItemIndex,double value)
{
if (ItemIndex <= m_aValeurAnalyse.Count-1 && ItemIndex >=0)
{
m_aValeurAnalyse[ItemIndex] = value;
}
}
public double GetItemValue(int ItemIndex)
{
if (ItemIndex <= m_aValeurAnalyse.Count - 1 && ItemIndex >= 0)
{
return (double)m_aValeurAnalyse[ItemIndex];
}
return -1;
}
protected override void OnDrawItem(DrawItemEventArgs e)
{
SolidBrush TempBrush = null;
if (DesignMode && this.Items.Count == 0)
base.OnDrawItem(e);
else
{
e.DrawBackground();
e.DrawFocusRectangle();
Rectangle Rect = e.Bounds;
if(this.Items.Count > 0)
{
if (GetSelected(e.Index))
{
TempBrush = new SolidBrush(Color.White);
if ((double)m_aValeurAnalyse[e.Index] > 0)
e.Graphics.FillRectangle(m_SBwrited, Rect);
else
e.Graphics.FillRectangle(m_SBunwrited,Rect);
}
else if ((double)m_aValeurAnalyse[e.Index] > 0)
{
TempBrush = m_SBwrited;
}
else
{
TempBrush = m_SBunwrited;
}
}
e.Graphics.DrawString(this.Items[e.Index].ToString(), Font, TempBrush, e.Bounds);
base.OnDrawItem(e);
}
}
protected override void OnMouseDown(MouseEventArgs e)
{
this.Invalidate();
base.OnMouseDown(e);
}
} |
Partager