Beispiel #1
0
        private bool InspectScrollBarAndTriggerEventIfNeeded()
        {
            bool ret = false;

            NativeMethods.Scrollinfo scrollinfo = new NativeMethods.Scrollinfo
            {
                Size = (uint)Marshal.SizeOf(typeof(NativeMethods.Scrollinfo)),
                Mask = (uint)Convert.ToInt32(ScrollInfoMask.SIF_ALL)
            };

            bool success = NativeMethods.GetScrollInfo(Handle, SB_VERT, ref scrollinfo);

            if (!success)
            {
                return(false);
            }

            if (ScrollInfoChanged(scrollinfo))
            {
                OnScrollValueChanged(scrollinfo);
            }

            if (scrollinfo.Position == 0)
            {
                OnScrollLimit(ScrollLimit.FirstLine);
                ret = true;
            }
            if (scrollinfo.Position + scrollinfo.Page - 1 == scrollinfo.Max)
            {
                OnScrollLimit(ScrollLimit.LastLine);
                ret = true;
            }
            lastScrollinfo = scrollinfo;
            return(ret);
        }
Beispiel #2
0
        private void OnScrollValueChanged(NativeMethods.Scrollinfo scrollinfo)
        {
            if (ScrollValueChanged == null)
            {
                return;
            }
            var value = new ScrollValueEventArgs(scrollinfo.Min, scrollinfo.Max, scrollinfo.Position);

            ScrollValueChanged(this, value);
        }
Beispiel #3
0
 private bool ScrollInfoChanged(NativeMethods.Scrollinfo scrollinfo)
 {
     if (lastScrollinfo.HasValue == false)
     {
         return(true);
     }
     if (scrollinfo.Position != lastScrollinfo.Value.Position)
     {
         return(true);
     }
     return(false);
 }
Beispiel #4
0
        private void SetScrollBar()
        {
            int sizeOfFile     = 10000000;
            int positionInFile = sizeOfFile / 2;

            NativeMethods.Scrollinfo scrollinfo = new NativeMethods.Scrollinfo();
            scrollinfo.Size     = (uint)Marshal.SizeOf(typeof(NativeMethods.Scrollinfo));
            scrollinfo.Mask     = (uint)Convert.ToInt32(ScrollInfoMask.SIF_ALL);
            scrollinfo.Min      = 0;
            scrollinfo.Max      = sizeOfFile; // for example the number of items in the control
            scrollinfo.Position = positionInFile;
            scrollinfo.Page     = 1;
            bool redraw            = true;
            int  scrollBoxPosition = NativeMethods.SetScrollInfo(Handle, SB_VERT, ref scrollinfo, redraw);//The return value is the current position of the scroll box.
        }