我正在製作一個winform .NET應用程序。它必須以條形格式顯示圖形。我使用的是一個picturebox,因爲這是我知道如何去做的唯一方法(如果有人知道更好的方法,請告訴我)。帶有動態寬度的WinForms Graphics PictureBox
我用這個代碼中動態添加行(圖形的條):
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++;
這一工程恰到好處。
我現在想要的是pictureBox有一個水平滾動條。所以我把pictureBox放到了autoscroll = true的面板中。現在我需要它來動態增加pictureBox的寬度。所以我添加這個代碼後,我添加每行:
pictureBox.Width = Math.Max(this.lineAmmount * (lineWidth + lineMargin), 205);
(205是我想要的最小寬度)。
該代碼也適用於greate。寬度增加。第一行Math.Max總是返回205,在幾行後它開始返回orher值。從那一刻起,所有的線路消失!
請幫忙!!
在此先感謝和抱歉,我的英語不好,
迭戈
看起來像你回答你的問題然後。 – 2010-09-27 15:50:16