Error using GDI+ DrawArc makes no sense "ArgumentException was unhandled by user code"

StackOverflow https://stackoverflow.com/questions/14961442

  •  10-03-2022
  •  | 
  •  

Question

See picture for the code generating the error. I've tried re-ordering things and it always happens on the second call to DrawArc. I simply copy pasted the line

g.DrawArc(SystemPens.ButtonFace, outerCircle[-1], 115, 220);

twice in a row to illustrate the error wasn't occurring because of a typo or miscalculation. It runs fine the first time, errors the second.Code generating error and error message

Code that calls ReLayout():

    public ButtonFan()
    {
        InitializeComponent();
        for (int i = 0; i < buttonLabels.Count(); i++)
        {
            buttonLabels[i] = new System.Windows.Forms.Label();
            this.buttonLabels[i].Name = "label"+i.ToString();
            this.buttonLabels[i].Size = new System.Drawing.Size(50, 23);
            this.buttonLabels[i].TabIndex = i;
            this.buttonLabels[i].Text = "label"+i.ToString();
        }
        ReLayout();
    }
Était-ce utile?

La solution

Turns out the error was generated in the FIRST

g.DrawArc(SystemPens.ButtonFace, outerCircle[-1], 115, 220);

statement. Still not sure why it didn't complain until the next one but the way I discovered it was by adding a line:

Console.WriteLine("Finished first arc");

after the first arc draw. The error then popped up on the Console.WriteLine. Of course Console.WriteLine wasn't erroring so that means it had to have rolled over from the previous statement which attempted to resize a rectangle to negative size and draw an arc in it.

Changing the [-1] to [150] solved the problem.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top