Scrolling & end scroll events
CompletedHi, is there any events that triggered when user stop scrolling?
Previously when I was using DataGridView, I able to detect user stop scroll by using the folliwing:
private bool addScrollHorizontalListener(DataGridView dgv)
{
bool ret = false;
Type t = dgv.GetType();
PropertyInfo pi = t.GetProperty("HorizontalScrollBar", BindingFlags.Instance | BindingFlags.NonPublic);
ScrollBar s = null;
if (pi != null)
{
s = pi.GetValue(dgv, null) as ScrollBar;
}
if (s != null)
{
s.Scroll += s_Scroll;
ret = true;
}
return ret;
}
private bool addScrollVerticalListener(DataGridView dgv)
{
bool ret = false;
Type t = dgv.GetType();
PropertyInfo pi = t.GetProperty("VerticalScrollBar", BindingFlags.Instance | BindingFlags.NonPublic);
ScrollBar s = null;
if (pi != null) {
s = pi.GetValue(dgv, null) as ScrollBar;
}
if (s != null) {
s.Scroll += s_Scroll;
ret = true;
}
return ret;
}
private void s_Scroll(object sender, ScrollEventArgs e)
{
if (e.Type == ScrollEventType.EndScroll) {
//Console.WriteLine("end scroll")
} else {
m_bDGVScrolling = true;
//Console.WriteLine("scrolling")
}
}
I've tried the below but it isn't what I looking for:
this.grid1.ScrollManager.VerticalScrollChanged += new EventHandler<Dapfor.Net.Ui.ScrollChangeEventArgs>(ScrollManager_VerticalScrollChanged);
private void ScrollManager_VerticalScrollChanged(object sender, Dapfor.Net.Ui.ScrollChangeEventArgs e)
{
}
-
Thank you for this question. Our grid is based on standard System.Windows.Forms control and as other controls it receives WM_ messages. Actual version of the grid doesn’t provide convenient interface with scroll information. Nevertheless you can create a class that derives from .Net Grid and you can retrieve needed scroll information from WinProc virtual method. Below you can see an example:
class CustomGrid : Grid
{
public const int WM_VSCROLL = 0x0115;
public const int SB_ENDSCROLL = 8;
protected override void WndProc(ref Message m)
{
bool endScroll = false;
switch (m.Msg)
{
case WM_VSCROLL:
int sbCode = (m.WParam.ToInt32()) & 0xFFFF;
switch (sbCode)
{
case SB_ENDSCROLL:
endScroll = true;
break;
}
break;
}
base.WndProc(ref m);
}
}
In the next version of .NetGrid we will add nested events for vertical and horizontal scrolling. By the way do you know that there are methods Row.EnsureVisible and Cell.EnsureVisible() that scroll rows and columns to ensure visible required elements?
Best regards,
The Dapfor Team0 -
Hi,
We have added Grid.Scroll event.
Best regards,
The Dapfor Team
0 -
following is my doing, but i hope Dapfor team would make it up. Because using winproc in 64 bit machine isn't support at all. I have to set my app target platform to x86 oni insteal of all/any platform.
using
System;
using
System.Collections.Generic;
using
System.Text;
using
Dapfor.Net.Ui;
using
System.Windows.Forms;
namespace
TCProPlus
{
public class DaphorCustomGrid : Grid
{
public delegate void DelegateEndScroll();
public event DelegateEndScroll EventEndScroll;
public delegate void DelegateEndScroll2(bool dragging);
public event DelegateEndScroll2 EventMouseDragging;
public const int WM_HSCROLL = 0x114;
public const int WM_VSCROLL = 0x0115;
public const int WM_MOUSEWHEEL = 0x20A;
public const int MK_CONTROL = 0x8;
public const int MK_LBUTTON = 0x1;
public const int MK_RBUTTON = 0x2;
public const int MK_MBUTTON = 0x10;
public const int MK_SHIFT = 0x4;
public event MouseEventHandler mwMouseWheel;
public const int SB_LINEUP = 0;
public const int SB_LINEDOWN = 1;
public const int SB_PAGEUP = 2;
public const int SB_PAGEDOWN = 3;
public const int SB_THUMBPOSITION = 4;
public const int SB_THUMBTRACK = 5;
public const int SB_TOP = 6;
public const int SB_BOTTOM = 7;
public const int SB_ENDSCROLL = 8;
protected override void WndProc(ref Message m)
{
int xpos = m.LParam.ToInt32() & 65535;
int ypos = m.LParam.ToInt32() / 65536;
int MouseKeys = m.WParam.ToInt32() & 65535;
int Rotation = m.WParam.ToInt32() / 65536;
int delta = Rotation / 120;
MouseButtons mb = new MouseButtons();
bool endScroll = false;
bool mouseClickHoldScrolling = false;
switch (m.Msg)
{
case WM_MOUSEWHEEL:
//Console.WriteLine("wheel");
OnMwMouseWheel(
new MouseEventArgs(mb, 0, xpos, ypos, delta));
break;
case WM_VSCROLL:
int sbCode = (m.WParam.ToInt32()) & 0xFFFF;
switch (sbCode)
{
case SB_ENDSCROLL:
endScroll =
true;
break;
case SB_LINEDOWN:
//Console.WriteLine();
break;
case SB_LINEUP:
//Console.WriteLine();
break;
case SB_PAGEDOWN:
//Console.WriteLine();
break;
case SB_PAGEUP:
//Console.WriteLine();
break;
case SB_THUMBTRACK:
mouseClickHoldScrolling =
true;
//Console.WriteLine();
break;
case SB_TOP:
//Console.WriteLine();
break;
case SB_BOTTOM:
//Console.WriteLine();
break;
case SB_THUMBPOSITION:
//Console.WriteLine();
break;
}
break;
}
if (EventEndScroll != null)
{
if (endScroll)
{
EventEndScroll();
}
}
if (EventMouseDragging != null)
{
if (mouseClickHoldScrolling)
{
EventMouseDragging(
true);
}
else
{
EventMouseDragging(
false);
}
}
base.WndProc(ref m);
}
protected virtual void OnMwMouseWheel(MouseEventArgs e)
{
if (mwMouseWheel == null) return;
mwMouseWheel(
this, e);
}
}
}
0 -
Hi, we will add a support for end scroll event in the next version of the grid. Best regards, The Dapfor Team 0
Please sign in to leave a comment.
Comments
4 comments