日期:2014-05-19  浏览次数:20728 次

关于C#滚动条的问题。散100!!
VScrollBar的Scroll事件处理函数
private   void   vScrollBar1_Scroll(object   sender,   System.Windows.Forms.ScrollEventArgs   e)

ScrollEventArgs.ThumbTrack处理滚动条正在被移动的消息。
如何区分是在向上滚动还是向下滚动??



------解决方案--------------------
OldValue 和NewValue 就可以判断了
------解决方案--------------------
private void AddMyScrollEventHandlers()
{
// Create and initialize a VScrollBar.
VScrollBar vScrollBar1 = new VScrollBar();

// Add event handlers for the OnScroll and OnValueChanged events.
vScrollBar1.Scroll += new ScrollEventHandler(
this.vScrollBar1_Scroll);
vScrollBar1.ValueChanged += new EventHandler(
this.vScrollBar1_ValueChanged);
}

// Create the ValueChanged event handler.
private void vScrollBar1_ValueChanged(Object sender,
EventArgs e)
{
// Display the new value in the label.
label1.Text = "vScrollBar Value:(OnValueChanged Event) " + vScrollBar1.Value.ToString();
}

// Create the Scroll event handler.
private void vScrollBar1_Scroll(Object sender,
ScrollEventArgs e)
{
// Display the new value in the label.
label1.Text = "VScrollBar Value:(OnScroll Event) " + e.NewValue.ToString();
}

private void button1_Click(Object sender,
EventArgs e)
{
// Add 40 to the Value property if it will not exceed the Maximum value.
if (vScrollBar1.Value + 40 < vScrollBar1.Maximum)
{
vScrollBar1.Value = vScrollBar1.Value + 40;
}
}

------解决方案--------------------
用一个变量把它的初始值保存后和移动后的值比较不行吗?