如何收到“滚动框”从DataGridView类型滚动事件? [英] How can I receive the "scroll box" type scroll events from a DataGridView?
问题描述
但是,当我拖动滚动框时,我仅获取类型为LargeDecrement和LargeIncrement的事件。
如何访问ThumbPosition,ThumbTrack,First,Last和EndScroll事件?
using System.Reflection;
使用System.Windows.Forms;
bool addScrollListener(DataGridView dgv)
{
bool ret = false;
类型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 + = new ScrollEventHandler(s_Scroll);
ret = true;
}
return ret;
}
void s_Scroll(object sender,ScrollEventArgs e)
{
// Hander去这里..
}
正如你所料,如果你想听水平滚动事件,你将VerticalScrollBar更改为HorizontalScrollBar
I have a DataGridView, and I'm listening to its Scroll event. This gives me a ScrollEventArgs object whose Type member is supposed to tell me the type of scroll event that has occurred. On the MSDN documentation page it says I should be able to detect movement of the scroll box by listening for events with types ThumbPosition, ThumbTrack, First, Last and EndScroll.
However, when I drag the scroll box, I only get events of type LargeDecrement and LargeIncrement.
How do I get access to the ThumbPosition, ThumbTrack, First, Last and EndScroll events?
using System.Reflection;
using System.Windows.Forms;
bool addScrollListener(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 += new ScrollEventHandler(s_Scroll);
ret = true;
}
return ret;
}
void s_Scroll(object sender, ScrollEventArgs e)
{
// Hander goes here..
}
As you'd expect, if you want to listen to horizontal scroll events, you change "VerticalScrollBar" to "HorizontalScrollBar"
这篇关于如何收到“滚动框”从DataGridView类型滚动事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!