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 ()
Version: 2.10.x
Hardware: PC All
: Lowest normal
Target Milestone: Community
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-03-11 18:11 UTC by pacholick
Modified: 2017-09-01 11:55 UTC (History)
2 users (show)

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

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

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.


Please create a new report for Bug 3850 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
NEW

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.