views:

18

answers:

2

Hello.

I'm making a winform .NET app. It must show a graphic in bars format. I'm using a picturebox because it's the only way I know how to do it (if someone knows a better way, please tell me).

I'm adding dynamically the lines (the bars of the graphic) with this code:

int currentX = this.lineAmmount * (lineWidth + lineMargin);
pictureBox.CreateGraphics().DrawLine(new Pen(color, lineWidth), //Pen
    currentX, pictureBox.Height, //Starting (x, y)
    currentX, pictureBox.Height - Convert.ToInt32(value * graphicsScale)); //Ending (x, y)
this.lineAmmount++;

That works just perfect.

What I want now is the pictureBox to have an horizontal scroll bar. So what I put the pictureBox into a panel with autoscroll = true. Now what I needed its to dynamically increase the pictureBox width. So I added this code after I add each line:

pictureBox.Width = Math.Max(this.lineAmmount * (lineWidth + lineMargin), 205);

(205 is the minimum width I want).

That code also works greate. The width is increased. With the first lines Math.Max always returns 205, after a couple of lines it starts returning the orher value. From that moment on ALL THE LINES DISAPPEAR!!!

Please help!!

Thanks in advance and sorry for my bad english,

Diego

+1  A: 

I found out the Chart control. It does all that automatically.

Diego
looks like you answered your question then.
Alex Essilfie
A: 

Where is written that code, that you posted in first box? Is it in update method of the control?

Sure, chart will be more appropriate here

Archeg