开发者

WinForms Graphics PictureBox with dynamic width

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


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜