3

I may be searching for the wrong question, but I'm not able to find an answer to this.

I have a panel with AutoScroll set to true. Controls are added to the panel dynamically. I need to fire an event when the scroll bars become visible, but I am unable to find such an event.

Any suggestions are appreciated.

More details:

  • This is a WinForms project.
  • The panel is a panel, System.Windows.Forms.Panel.
  • The panel is visible.
  • AutoScroll is set to true.
  • I want to execute some code when AutoScroll makes the scrollbars visible.
Johnie Karr
  • 2,744
  • 2
  • 35
  • 44
  • can you explain what you want to do a bit more in detail..? are you using a `panel` or `update panel`..? is this `winforms` or `web forms?` also do you mean when the form is visible? or are you setting the panel visible based on a `Button Click Event`? please clarify – MethodMan Feb 08 '13 at 16:20
  • @DJKRAZE, I have provided more details. To your questions specifically, 1) Winforms, 2) no, I mean when the scroll bars are visible, 3) no, the panel is always visible – Johnie Karr Feb 08 '13 at 16:24
  • 1
    you need to check the OnPaint method like here: http://stackoverflow.com/questions/4305011/c-sharp-panel-for-drawing-graphics-and-scrolling – MUG4N Feb 08 '13 at 16:27
  • Thanks @MUG4N, I posted the basics of my solution as an answer. – Johnie Karr Feb 08 '13 at 17:57

2 Answers2

1

Thanks to the comment made by @MUG4N on the original question, here is the solution. My current project is in VB.Net, and so is the solution.

canvas is the name of the panel.

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

To check the Horizontal Scroll, use Me.canvas.HorizontalScroll.Visible

Important

Make sure you put some checks in place to avoid an infinite loop.

Johnie Karr
  • 2,744
  • 2
  • 35
  • 44
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"....
Hiren
  • 41
  • 1
  • You correct about the scroll method, but this would be fired when the form is scrolled, which is not what I'm looking for. – Johnie Karr Feb 08 '13 at 17:40