Bug 3850 - ScrollEventArgs in Form_Scroll method has invalid values
Summary: ScrollEventArgs in Form_Scroll method has invalid values
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: Windows.Forms (show other bugs)
Version: 2.10.x
Hardware: PC All
: Lowest normal
Target Milestone: Community
Assignee: Bugzilla
Depends on:
Reported: 2012-03-11 18:11 UTC by pacholick
Modified: 2017-09-01 11:55 UTC (History)
2 users (show)

See Also:
Tags: mono-community
Is this bug a regression?: ---
Last known good build:


Description pacholick 2012-03-11 18:11:00 UTC
e.ScrollOrientation is HorizontalScroll even if I'm scrolling vertically
e.OldValue is always -1
e.NewValue is correct
Comment 1 lyfjxymf 2014-10-18 04:19:51 UTC
This bug has not been fixed in 
Mono JIT compiler version 3.2.8 (Debian 3.2.8+dfsg-4ubuntu1)

So I am having trouble with Scrollable Controls:

private void panel1_Scroll(object sender, ScrollEventArgs e)
	if (e.ScrollOrientation == ScrollOrientation.HorizontalScroll)
		dest.HorizontalScroll.Value = e.NewValue;
	else if (e.ScrollOrientation == ScrollOrientation.VerticalScroll)
		dest.VerticalScroll.Value = e.NewValue;

	this.Text = e.ScrollOrientation + "";
	//Mono Bug!!!
Comment 2 lyfjxymf 2014-10-18 04:54:26 UTC
If you want to synchronize Scroll Positions of two controls, simply write:

private void panel1_Scroll(object sender, ScrollEventArgs e)
    panel2.HorizontalScroll.Value = panel1.HorizontalScroll.Value;
    panel2.VerticalScroll.Value = panel1.VerticalScroll.Value;
private void panel2_Scroll(object sender, ScrollEventArgs e)
    panel1.HorizontalScroll.Value = panel2.HorizontalScroll.Value;
    panel1.VerticalScroll.Value = panel2.VerticalScroll.Value;

If you want to use the e.ScrollOrientation:

private ScrollOrientation? CheckOrientation(ScrollableControl dest, ScrollEventArgs e)
	if (oldH == null || oldV == null)
		oldH = dest.HorizontalScroll.Value;
		oldV = dest.VerticalScroll.Value;
		return null;

	ScrollOrientation? o = null;

	int newH = dest.HorizontalScroll.Value;
	int newV = dest.VerticalScroll.Value;

	//You could only click on one scroll bar at one time.
	if (newH - oldH != 0)
		o = ScrollOrientation.HorizontalScroll;
	else if (newV - oldV != 0)
		o = ScrollOrientation.VerticalScroll;

	oldH = oldV = null;
	return o;

int? oldH = null;
int? oldV = null;

private void panel1_Scroll(object sender, ScrollEventArgs e)
	this.Text =
	CheckOrientation(panel1, e) + "";

But this piece of code is not perfect. It requires user to scroll for a longer distance, and it is slow.

Notice (2018-05-21): bugzilla.xamarin.com will be switching to read-only mode on Thursday, 2018-05-25 22:00 UTC.

Please join us on Visual Studio Developer Community and GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs and copy them to the new locations as needed for follow-up. The See Also field on each Bugzilla bug will be updated with a link to its new location when applicable.

After Bugzilla is read-only, if you have new information to add for a bug that does not yet have a matching issue on Developer Community or GitHub, you can create a follow-up issue in the new location. Copy and paste the title and description from this bug, and then add your new details. You can get a pre-formatted version of the title and description here:

In special cases you might also want the comments:

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Note You need to log in before you can comment on or make changes to this bug.