-2

I have a c# form which is to allow the user to specify a differential equation (dy/dt = -lambda*y) to solve both exactly and approximately (by entering desired values of the intital condition, time step and lambda into textBoxes). Clicking a button calculates the solutions and displays them numerically in boxes as they change over time (using a timer). When the timer finishes, 'Simulation Completed' is displayed in a MessageBox.

At this point, clicking the 'draw graph' button invokes zedGraph to graph the exact and approximate solutions. There are no problems wih calculating and graphing the solutions. The problem is that the label and textBox for timeStep (which I added after adding the zedGraph section) and the 'draw graph' button are superimposed on the graph, partially obscuring it. The textBoxes and labels for lambda and the initial condition were added to the program before the zedGraph part and don't get superimposed.

Is there a way to stop the timeStep label and textBox from being superimposed without having to write the program again, adding the textBox before the zedGraph section?

To summarise: the order in which you add things (at least the way I've done it, if not in general) determines wha happens: adding a textBox before adding the zedGraph section means it doesn't get superimposed on the graph. Add a textBox after adding the zedGraph section and it does get superimposed on the graph. I'm looking for a way o be able to add extra features, having already added the zedGraph section, without them being superimposed on the graph.

You can view 3 screenshots, 2 from before the problem was solved and 1 after here:

https://www.facebook.com/photo.php?fbid=10201376481749572&set=a.10201375193157358.1073741826.1099868090&type=3&theaterset=a.10201375193157358.1073741826.1099868090&type=3&theater

This is a screenshot of the problem:

labels obscuring graph

George Tomlinson
  • 1,871
  • 3
  • 17
  • 32
  • How about just moving things out of the way of the graph? You haven't given us nearly enough information about this problem to actually help you solve it. Why do you need to write the program again, why not just change the existing program? – Lasse V. Karlsen Aug 21 '13 at 21:48
  • Please add paragraphs, your question hurts my eyes (press enter twice) – Sayse Aug 21 '13 at 21:54
  • 1
    As far as I can tell this is a question about form layout, not about differential equations. The title ought to reflect that. – H H Aug 21 '13 at 21:56
  • I can move them out of the way of the graph, but I don't think it looks as good. I would prefer to change the existing program: that's what I'm trying to find out how to make work. The reason writing the program again should work is because the order in which the various items are inserted (in particular, whether a given item is inserted before or after the zedGraph uer control is added) determines whether or not it then appears on the graph. So if I add the zedGraph user control after everything else, I think this might work, but it's a bit long-winded. @ Lasse V. Karlsen – George Tomlinson Aug 21 '13 at 22:02
  • Maybe the best solution is to have a button on the existing form which loads a new form which is then used solely to draw rthe graph with zedGraph, if this is possible. – George Tomlinson Aug 21 '13 at 22:10
  • Thanks for the more sensible title, whoever edited it. (I guess Henk Holterman). – George Tomlinson Aug 21 '13 at 22:14
  • I think a picture would be very helpful for your (unclear) question, if you add the link to the *bottom* of your question, someone will be able to add the formatting to it – Sayse Aug 21 '13 at 22:15
  • Thanks also to the person who added the winforms tag. – George Tomlinson Aug 21 '13 at 22:16
  • I have a picture of the graph in a file, but I'm afraid I don't know how to add this @ Sayse – George Tomlinson Aug 21 '13 at 22:21
  • Actually, I've just noticed that in the picture of the graph in the file I just mentione din the comment above, the textBox, label and button aren't there, but this doesn't solve the problem, as they still appear in Visual Studio. I don't know how to take a screenshot of the obscured graph in Visual Studio, but I'd be happy to if someone can tell me how @ Sayse – George Tomlinson Aug 21 '13 at 22:37
  • Initially I didn't have zedGraph involved. I just had a form which computed the values of the exact and approximate solutions for each of the 20/timeStep time points. So with timeStep 1, that would be 20 values each, starting at t = 0, ending with t = 19. As the timer ran from 0 to 19, each of the corresponding calculated y values would be displayed in the corresponding boxes (labelled 'Exact Solution' and 'Approximate Solution' accordingly) in real time. I then introduced zedGraph so I could plot the results. – George Tomlinson Aug 22 '13 at 00:32
  • I began by followoing steps 1-7 under the heading 'Using ZedGraph as a UserControl' on the following page: http://www.codeproject.com/Articles/5431/A-flexible-charting-library-for-NET However, I found that doing this produced a graph immediately and I was unable to access any of the former functionality, so I couldn't run the simulation to calculate and display the results in the boxes labelled 'Exact Solution' and 'Approximate Solution' mentioned above, which was a feaure I wanted to retain. – George Tomlinson Aug 22 '13 at 00:35
  • I overcame this problem by creating a button which I called 'draw graph' and transferring the code which had been in a method which caused the graph to be produced immediately (called 'Form1_load') to the method 'button2_Click' so that the graph wasn't created until this button was clicked. Things were now fine until i decided to add 2 boxes allowing the user to enter the timeStep and timer interval, which now get superimposed on the graph, as i mentioned above. I'm looking for an easy fix, if possible. I think copying and pasting everthing into a new project but adding the zedGraph part – George Tomlinson Aug 22 '13 at 00:38
  • last will work, but it's a bit awkward. It would be good to find an easier method, in case there are other thing I want to add later which start getting superimposed on the graph as well. I wouldn't expect a box to be superimposed on the graph by default: perhaps the way I've built this project is unusual or the design is flawed. The other possible solution taht's occurred to me would be to have a button on the form which loads a new form and then the zedGraph features are only avaiolable from the second form. I guess this should be ok as long as there are no problems passing the – George Tomlinson Aug 22 '13 at 00:42
  • necessary data values to plot from Form1.cs to Form2.cs. – George Tomlinson Aug 22 '13 at 00:43

1 Answers1

1

I just worked out the answer (thanks to God): I just hide the objects I don't want to appear on the graph using the Hide() method at the start of my createGraph() method as follows:

private void CreateGraph(ZedGraphControl zgc)
{

    textBox3.Hide();
    textBox4.Hide();
    label3.Hide();
    label5.Hide();
    button2.Hide();

Thanks everyone for your input. Quite easy in the end, thankfully... what a relief.

Here's a link to the finished graph: https://www.facebook.com/photo.php?fbid=10201375420003029&set=a.10201375193157358.1073741826.1099868090&type=3&theater

George Tomlinson
  • 1,871
  • 3
  • 17
  • 32
  • You can view 3 screenshots, 2 from before the problem was solved and 1 after here: https://www.facebook.com/photo.php?fbid=10201376481749572&set=a.10201375193157358.1073741826.1099868090&type=3&theaterset=a.10201375193157358.1073741826.1099868090&type=3&theater – George Tomlinson Aug 22 '13 at 16:31