This is Xamarin's bug tracking system. For product support, please use the support links listed in your Xamarin Account.
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: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-03-11 18:11 UTC by pacholick
Modified: 2014-10-18 04:54 UTC (History)
2 users (show)

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


Attachments

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.

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