C # ScrollableControl doesn't receive all scroll events

I got a problem with ScrollableControl (more precise panel). When the mouse pointer is scrolled directly on the scrollbar, the scroll event is fired correctly.

But when scrolling with the mouse wheel, the pane scrolls correctly but the Scroll event is not fired.

Also, when an out-of-bounds control within a panel receives focus, the panel scrolls correctly to display the control, but in this case the Scroll event is not fired.

Have any of you experienced the same thing? Have you found a solution?

Thank!

+3


source to share


1 answer


Update: I have now tested - this does NOT work!

I haven't tested it yet, but according to this: http://www.codeproject.com/Articles/7452/ScrollableControl-with-Scroll-Events one option is to extend ScrollableControl functionality



The code looks like this:

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;
        }
    }
}

      

0


source







All Articles