locked
"Parameter is not valid" on Graphics.DrawLine RRS feed

  • Question

  • Hello,

    My program runs smoothly most of the time, but I have found in testing that it seems I get a random error when the program calls the graphics.drawline function. It happens when I am trying to draw a line from one picturebox to another. The error is not informative, but it does say:

    "An unhandled exception of type 'System.ArgumentException' occurred in System.Drawing.dll

    Additional Information: Parameter is not valid"

    It is weird because sometimes it will take me a long time to reproduce this error, yet sometimes it is on the first line I draw. Here is the line that has the problem:

    g->DrawLine(eraser,lineStart.X,lineStart.Y,oldMouse.X,oldMouse.Y);

    All of the variables are instantiated and have values. Does anyone have any information that can help me?

    Thanks.

    Monday, December 21, 2009 3:02 PM

Answers

  • Hello,

    Please make sure your objects 'g' and 'eraser' are valid and are not collected by the Garbage Collection, and also doesn't call Dispose() too early.
    It's hard to guess out what's the reason caused the ArgumentException, could you please give us more code snippet to test?

    And I suggest posting WinForm question at Windows Forms General forum.

    Sincerely,
    Wesley
    Please mark the replies as answers if they help and unmark them if they provide no help. Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by higgernaut Wednesday, December 23, 2009 2:34 PM
    Wednesday, December 23, 2009 4:43 AM

All replies

  • Hello,

    Please make sure your objects 'g' and 'eraser' are valid and are not collected by the Garbage Collection, and also doesn't call Dispose() too early.
    It's hard to guess out what's the reason caused the ArgumentException, could you please give us more code snippet to test?

    And I suggest posting WinForm question at Windows Forms General forum.

    Sincerely,
    Wesley
    Please mark the replies as answers if they help and unmark them if they provide no help. Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by higgernaut Wednesday, December 23, 2009 2:34 PM
    Wednesday, December 23, 2009 4:43 AM
  • I found that there was one scenario where the graphics object was disposed, and this is why the error seemed random.

    Thank you for your help.

    Wednesday, December 23, 2009 2:36 PM