2015-06-11 33 views
3

我遇到了ScrollableControl(面板更精确)的问题。当直接在滚动条上滚动鼠标指针时,滚动事件被正确触发。C#ScrollableControl没有收到所有滚动事件

但是,使用鼠标滚轮滚动时,面板会正确滚动,但不会触发滚动事件。

同样,当出界控制面板内接收到焦点,小组正确滚动带来鉴于控制,但再次,在这种情况下,将不会触发Scroll事件。

你们有没有经历过同样的事情?你找到解决方案吗?

谢谢!

回答

0

更新:我现在已经测试 - 这不起作用!

我没有测试过,但根据该:http://www.codeproject.com/Articles/7452/ScrollableControl-with-Scroll-Events 一个选项被扩展的ScrollableControl

的代码的功能如下:

using System; 
using System.ComponentModel; 
using System.Windows.Forms; 
using System.Diagnostics; 

namespace Foretel.SelectAGrid 
{ 
    /// <summary> 
    /// Adds the missing scroll events to the scrollable control! 
    /// Written by Martin Randall - Thursday 17th June, 2004 
    /// </summary> 
    public class ScrollableControlWithScrollEvents : ScrollableControl 
    { 
     private const int WM_HSCROLL = 0x114; 
     private const int WM_VSCROLL = 0x115; 

     /// <summary> 
     /// Horizontal scroll position has changed event 
     /// </summary> 
     public event ScrollEventHandler HorzScrollValueChanged; 

     /// <summary> 
     /// Vertical scroll position has changed event 
     /// </summary> 
     public event ScrollEventHandler VertScrollValueChanged; 

     /// <summary> 
     /// Intercept scroll messages to send notifications 
     /// </summary> 
     /// <param name="m">Message parameters</param> 
     protected override void WndProc(ref Message m) 
     { 
      // Let the control process the message 
      base.WndProc (ref m); 

      // Was this a horizontal scroll message? 
      if (m.Msg == WM_HSCROLL) 
      { 
       if (HorzScrollValueChanged != null) 
       { 
        uint wParam = (uint)m.WParam.ToInt32(); 
        HorzScrollValueChanged(this, 
         new ScrollEventArgs( 
          GetEventType(wParam & 0xffff), (int)(wParam >> 16))); 
       } 
      } 
      // or a vertical scroll message? 
      else if (m.Msg == WM_VSCROLL) 
      { 
       if (VertScrollValueChanged != null) 
       { 
        uint wParam = (uint)m.WParam.ToInt32(); 
        VertScrollValueChanged(this, 
         new ScrollEventArgs( 
         GetEventType(wParam & 0xffff), (int)(wParam >> 16))); 
       } 
      } 
     } 

     // Based on SB_* constants 
     private static ScrollEventType [] _events = 
      new ScrollEventType[] { 
             ScrollEventType.SmallDecrement, 
             ScrollEventType.SmallIncrement, 
             ScrollEventType.LargeDecrement, 
             ScrollEventType.LargeIncrement, 
             ScrollEventType.ThumbPosition, 
             ScrollEventType.ThumbTrack, 
             ScrollEventType.First, 
             ScrollEventType.Last, 
             ScrollEventType.EndScroll 
            }; 
     /// <summary> 
     /// Decode the type of scroll message 
     /// </summary> 
     /// <param name="wParam">Lower word of scroll notification</param> 
     /// <returns></returns> 
     private ScrollEventType GetEventType(uint wParam) 
     { 
      if (wParam < _events.Length) 
       return _events[wParam]; 
      else 
       return ScrollEventType.EndScroll; 
     } 
    } 
}