2

我可能正在寻找错误的问题,但我无法找到答案。

我有一个将 AutoScroll 设置为 true 的面板。控件被动态添加到面板中。当滚动条变得可见时,我需要触发一个事件,但我找不到这样的事件。

任何建议表示赞赏。

更多细节:

  • 这是一个 WinForms 项目。
  • 面板是一个面板,System.Windows.Forms.Panel。
  • 面板可见。
  • 自动滚动设置为真。
  • 当 AutoScroll 使滚动条可见时,我想执行一些代码。
4

2 回答 2

1

感谢@MUG4N 对原始问题的评论,这是解决方案。我目前的项目在 VB.Net 中,解决方案也是如此。

canvas 是面板的名称。

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

重要的

确保进行一些检查以避免无限循环。

于 2013-02-08T17:56:55.577 回答
0
    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"....
于 2013-02-08T17:39:28.147 回答