[C#] DrawItem Problem

04/05/2014 20:35 _Roman_#1
Hi,

ich habe folgendes Problem. Wenn ich bei meiner ListBox einen normalen Mausklick mache, kommt eine ArgumentOutOfRangeException. In den Details steht dann irgendwas mit DrawItem Ereignis. Das Komische dabei ist, dass es nicht passiert, wenn ich das Programm über die IDE öffne. Ich habe es mit AdvancedInstaller in einen Installer gepackt und installiert. Und nur bei der installierten Form tritt der Fehler auf.
Hier der dazugehörige DrawItem Code

Code:
        public void epDraw(DrawItemEventArgs ev, ListBox objectives, int current)
        {
            //set red or green text color, depends on objective status
            ev.DrawBackground();
            int i = ev.Index;

            Font myfont = ev.Font;
            Brush mybrush;
            mybrush = Brushes.Red;

            switch (Projectmethods.Access.Marks[current][i])
            {
                case true:
                    mybrush = Brushes.Green;
                    myfont = new Font("Comic Sans MS", 12.25f, FontStyle.Strikeout);
                    break;

                case false:
                    mybrush = Brushes.Red;
                    myfont = new Font("Comic Sans MS", 12.25f);
                    break;
            }

            ev.Graphics.DrawString(objectives.Items[i].ToString(), myfont, mybrush, ev.Bounds);
            objectives.Update();
        }