Form closing unexpectedly

juggernot

Well-known member
Joined
Sep 28, 2006
Messages
173
Programming Experience
Beginner
I've attached the solution in which I'm getting the error. The first form is where the user inputs all the information needed to display a graph. The second is where the graph is created. I'm not nearly completed yet, I'm just focusing on setting up a grid according to user input. To keep the graph from getting out of hand, I've made it so that the intervals(gridlines) cannot be less than 40 pixels apart. If this happens you recieve an error, and the graph form closes. After this happens I recieve an error that says cannot access a disposed object named "Graph". Then my project breaks and the first form closes, and I don't want that. Could someone tell me where I made my mistake?

And I realize that my intervals should start from the origin and move out, not start from one end of the graph and go to the other, maybe missing the origin altogether. I will fix this eventually.
 

Attachments

  • Graphing.zip
    11.9 KB · Views: 14
Last edited by a moderator:
I get overflow error no matter what values I input. What values is expected?
 
That's strange. I've only gotten overflow values with really high numbers. I usually test with the max at 100, the min at 0 and the interval at 10.That is succesful, if not finished. If your trying to test my error by using big numbers, a max-min = 1000 with an interval of 1 will do it. You don't need to worry about the actual formula for the line/parabola/wave. That doesn't work yet. Just put some zeros in there to be safe.
 
Do the limit check in Form load instead and close before form is shown. Since the setup form is specialized for the display form you could better do the check there and not try to show the display form at all if the input values is not approved. Also a tip for the setup form, use NumericUpDown or Trackbar control to let user choose values between interval. For painting you DO NOT use CreateGraphics, the paint event already provide you with the graphics instance by event parameter e.Graphics.
 
I've changed it so It checks for the error on the first form, and removed the me.creategraphics. After doing this, and some general editing I noticed that the graphing form broke when I tried to graph. I get an 'object reference not set to an instant of an object' error, with 'public class setup' selected, :mad: . Before I get the error, the second form shows up. I'm thinking the source of the errror comes from the paint section. Any Idea what it could be?
 
nevermind, I fixed my error. I forgot to replace my graphics variable with e.graphics. It's working now.
 
Back
Top