2013-02-08 173 views
2

我可能在尋找錯誤的問題,但我無法找到對此的答案。面板 - 滾動條可見事件

我有一個AutoScroll設置爲true的面板。控件將動態添加到面板。當滾動條變得可見時,我需要觸發一個事件,但我無法找到這樣的事件。

任何建議表示讚賞。

更多細節:

  • 這是一個WinForms項目。
  • 該面板是一個面板System.Windows.Forms.Panel。
  • 面板可見。
  • AutoScroll設置爲true。
  • 我想在AutoScroll使滾動條可見時執行一些代碼。
+0

你能解釋一下你想做些什麼嗎?你在使用「面板」還是「更新面板」?這是'winforms'還是'web forms?'也是你的意思,當窗體是可見的?或者你是否可以根據「Button Click Event」設置面板?請澄清 – MethodMan 2013-02-08 16:20:25

+0

@DJKRAZE,我提供了更多細節。具體來說,1)Winforms,2)否,我的意思是當滾動條可見時,3)否,面板始終可見 – 2013-02-08 16:24:42

+1

您需要檢查OnPaint方法,如下所示:http://stackoverflow.com/問題/ 4305011/c-sharp-panel-for-drawing-graphics-and-scrolling – MUG4N 2013-02-08 16:27:21

回答

1

多虧了@ MUG4N在原來的問題提出的意見,這裏是解決方案。我目前的項目是在VB.Net,解決方案也是如此。

畫布是面板的名稱。

Private Sub canvas_Paint(sender As Object, e As PaintEventArgs) Handles canvas.Paint 
    If Me.canvas.VerticalScroll.Visible Then 
      ' Do stuff here 
    End If 
End Sub 

要檢查水平滾動,使用Me.canvas.HorizontalScroll.Visible

重要

確保你把一些檢查到位,以避免無限循環。

-1
private void Form1_Load(object sender, EventArgs e) 
    { 
     Int32 x = 20; 
     Int32 y = 20; 
     for (Int32 i = 0; i < 20; i++) 
     { 
      Button btn = new Button(); 
      btn.Name = "btn" + i.ToString(); 
      btn.Location = new Point(x, y); 
      x = x + 20; 
      panel1.Controls.Add(btn); 
     } 
     //call(1, new List<long> { 1, 2, 3, 4 }); 
    } 
    private void **panel1_Scroll**(object sender, ScrollEventArgs e) 
    { 
     MessageBox.Show("scroll"); 
    } 




panel control have its own method "Scroll" see events of panel control and find the "Scroll".... 
+0

你糾正了滾動方法,但是當窗體滾動時這會被觸發,這不是我正在尋找的。 – 2013-02-08 17:40:54