How can I prevent a scrollbar to scroll when user selects a tab?

  • Thread starter Thread starter Pedro Rosas Silva
  • Start date Start date
P

Pedro Rosas Silva

Hello,

I have a windows form with a TabControl "tabControl1" (with 2 tabs)
inside it.
Inside "tabControl1", I have another TabControl "tabControl2" (also with
2 tabs).

I have set the "AutoScroll" property of the form to true.

The problem is that when the scrollbars are showing up, if the user
clicks one of the tabs, the scrollbar rolls down to it.
I don't want this behaviour. I want the scrollbar to retain its position.

Does anyone know how can I do it?
Thank you in advance.

Best Regards,
Pedro Rosas
 
(...)
The problem is that when the scrollbars are showing up, if the user
clicks one of the tabs, the scrollbar rolls down to it.
I don't want this behaviour. I want the scrollbar to retain its position.
(...)

The problem is that you can't change this bahavior. The solution is to
update the scrollbar position after it's "auto update". Next problem is that
it is "auto updated" after events handlers so to overcome this we have to
send windows message. The solution:

public delegate void AutoScrollPositionDelegate(ScrollableControl ctrl,
Point p);

//Some control gain focus
private void Control_Enter(object sender, System.EventArgs e)
{
Point p = this.AutoScrollPosition;
AutoScrollPositionDelegate del = new
AutoScrollPositionDelegate(SetAutoScrollPosition);
Object[] args = { this, p };
BeginInvoke(del, args);
}

private void SetAutoScrollPosition(ScrollableControl ctrl, Point p)
{
p.X = Math.Abs(p.X);
p.Y = Math.Abs(p.Y);
ctrl.AutoScrollPosition = p;
}

Dawid Rutyna
 
Back
Top