0

I am currently writing a program where I need to draw some graph's. I need to have a little bit specific layout in these graphs. For example I have three stages of a length in days defined by the user. a start stage of for example 30 days, a mid stage of 40 and an end stage of 20 days. These stages I want to have all a different backgroundcolor in the graph. I do that by drawing pictureboxes and adapting their widths to the stage lengths. Also for every day in the total length I want to draw a vertical line and for the amount of horizontal lines in the graph I take the maximum of y = f(x).

y = f(x) needs to be plotted on the graph. For I use many pictureboxes on the background I cannot use the graphics.DrawLine for it will be drawn behind the pictureboxes. So I decided to make the line with an array of pictureboxes ;) It works fine, but obviously it takes a lot of time to load the program now.

Is there another way to draw this graph using arrays of controls that require less effort from the computer? Or should I completely stop with the arrays?

(I wanted to post my picture here, but I don't have ten reputation yet because I'm a noobie :( )

Later on I will add more lines to this graph, but since I figured that my program is already slowing down I ceased programming those other lines and went to the all-knowing forum!

Any help will be much appreciated!

Greetz, Arrie

Arrie
  • 15
  • 6
  • _For I use many pictureboxes on the background I cannot use the graphics.DrawLine for it will be drawn behind the pictureboxes_ This makes no sense. You can easily draw onto the PictureBoxes! Actually you don't even need three of them, just draw 3 filledRectangles! You really need to learn about Graphics and drawing in the Paint event of controls, no matter if they are Pictureboxes or Panels. !! And don't draw on the form as you seem to do! – TaW Oct 23 '14 at 23:10

2 Answers2

0

The common form controls aren't really suitable for this purpose. I'd suggest taking a look at using libraries that give you more power and control over visuals and graphics.

Kári
  • 16
  • 1
0

@Kári is right:

If you want to stay with .NET only (no 3rd library dependence) you can use GDI. In .NET you can use by including System.Drawing.dll as an reference.

One simple yet correct approach would be:

  1. create a target control (picturebox for example)
  2. implement the OnPaintDraw Event which gives you an Graphics object that contains many drawing methods. See MSDN for more information: MSDN -> Graphics

The methods of Graphics will always draw above the control, so make sure your target control is visible an not behind any other control. If GDI is not enough you can check out other libraries. (See .NET graph library around?)

Community
  • 1
  • 1
Aurus
  • 705
  • 9
  • 21