2015-05-29 70 views
0

面板出現問題。 我添加指向一個面板與此代碼:當值超出邊界時,面板自動滾動

void panelDraw_Paint(object sender, PaintEventArgs e) 
{ 
    if (this.MeasuredValue == null) 
     return; 

    var g = e.Graphics; 

    int x = 0; 

    foreach (value m in this.MeasuredValue) 
    { 
     double percentage = m.MeasuredValue [(int)this.MeetType].GetValueOrDefault()/this.MaxValue * (double)100; 
     double y = this.Height/(double)100; 
     double pixels = y * percentage; 
     g.DrawRectangle(Pens.Green, x++, this.Height - (int)pixels, 1, 1); 
     g.DrawLine(Pens.GhostWhite, 0, this.Height/4, panelDraw.Width, this.Height/4); 
     g.DrawLine(Pens.GhostWhite, 0, this.Height/2, panelDraw.Width, this.Height/2); 
     g.DrawLine(Pens.GhostWhite, 0, (this.Height/4) * 3, panelDraw.Width, (this.Height/4) * 3); 
     if (x > panelDraw.Width) 
     { 
      panelDraw.AutoScroll = true; 
     } 
    } 
} 

我的面板的尺寸爲230; 218 I'ld喜歡看我的點當x熄滅的邊界(更大然後230)但不知何故自動滾屏不起作用.. 我也從一開始就在面板屬性上設置了AutoScroll爲true,但這也行不通。

這是我所得到的,當x比我的面板寬度較大:

http://i60.tinypic.com/5fp7ur.jpg

我怎麼能看到我點的時候,他們都出了面板的邊界?

回答

0

面板不顯示任何滾動條的原因是它不知道其內容的任何內容。即使它將滾動,視圖也不會改變,因爲在繪製內容時不考慮滾動位置。

而不是直接繪製到面板上,你應該添加適當大小的另一個控件,並在該控件上繪製。這將給面板提供必要的滾動提示,而且您不必手動處理滾動。