[ACCEPTED]-Windows : how to make the panel scroll bar to be at the TOP position on loading the form-winforms

Accepted answer
Score: 10

You need select the first element of your 2 panel for the vertical scrollbar appear 1 at top:

Score: 8

On load, try to set the panel's VerticalScroll 12 property to 0

panel1.VerticalScroll.Value 11 = 0;

EDIT: Assuming you have panel1.AutoScroll 10 = true

Setting the vertical scroll value 9 to 0 will scroll to the top, however the 8 vertical slider won't.

Also, maybe you have 7 some control at the bottom of the panel 6 that gets the focus (that should force the 5 panel to scroll down). Setting the focus 4 to the text box at the top of the panel 3 will keep the scroll on top. (but then again 2 maybe you don't want to set the focus to 1 a control at the top)

Score: 1

I had the same problem, but with my own 9 user control. I tried many things to try 8 and get the panel to scroll back to the 7 top after populating it with many controls.

Nomatter 6 what I did it always put the VScroll bar 5 to the bottom.

After exhaustive testing I 4 found it was because my controls had the 3 TabStop property set to true (default on user controls) was 2 causing the issue.

Setting TabStop to false fixed 1 it.

Score: 1

In my case am using the followin' code

//to initialize the position of the panel 
panel5.AutoScrollPosition = new Point(panel5.AutoScrollPosition.X, 0);
//to initialize the position of the scroll bar
VScrollBar1.Value = 0;


Score: 0

If there are many controls added in a form, then 5 set the tabIndex property sequentially from 4 top to bottom. the scroll bar will set at 3 top if any of the top control's tab index 2 is lesser than tab index of any of the bottom 1 control's tab index. This resolved my issue.

Score: 0

I had a case where I was working on a shopping 19 app, I had an item list UserControl that contained 18 a vertical list of line item UserControls (all Dock=DockStyle.Top, if 17 that paints a picture), and I was sending 16 a list of items to a method in the item 15 list control and just creating and adding 14 all the item controls to a panel.

Not only 13 was the control appearing scrolled all the 12 way to the bottom, but the items were all 11 in reverse order. The list was in the correct 10 sorted order, but when I sent each one to 9 the ItemListControl.Controls.Add() method, it put them in reverse order. I 8 fixed it by using SetChildIndex() to place them in reverse 7 order.

public void Add(ItemControl itemControl)
    _itemPanel.Controls.SetChildIndex(itemControl, 0);

Now that I think about it, DockStyle.Top might 6 actually be why they're getting added in 5 reverse order. It's hard to tell because 4 if I change the DockStyle to something else, the 3 controls are not all showing up.

Anyway, getting 2 the controls inserted in the correct order 1 fixed the scrolling problem.

Score: 0

I found that provided you have Autoscroll 7 set to True on any control which has that 6 property you can say at any time:

'Scroll 5 to the top of a Control '(substitute Control's 4 name in following without "[" and 3 "]" symbols)

  [ControlName].AutoScrollPosition = New Point(0, 0)

'Scroll to the bottom 2 of a Control '(substitute Control's name 1 in following without "[" and "]" symbols)

  [ControlName].AutoScrollPosition = New Point(0, [ControlName].Height)

More Related questions