Bug 3850

Summary: ScrollEventArgs in Form_Scroll method has invalid values
Product: [Mono] Class Libraries Reporter: pacholick
Component: Windows.FormsAssignee: Bugzilla <bugzilla>
Status: NEW ---    
Severity: normal CC: lyfjxymf, mono-bugs+mono
Priority: Lowest    
Version: 2.10.x   
Target Milestone: Community   
Hardware: PC   
OS: All   
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.