Exemple #1
0
 private static Win32.SCROLLINFO VScrollInfo(TextBoxBase richTextBox, int mask)
 {
     Win32.SCROLLINFO info = new Win32.SCROLLINFO();
     info.fMask  = mask;
     info.cbSize = Marshal.SizeOf(info.GetType());
     Win32.GetScrollInfo(richTextBox.Handle, Win32.SB_VERT, ref info);
     return(info);
 }
Exemple #2
0
			/// <summary>
			/// gets the position where the scroll thumb is released
			/// </summary>
			public int GetScrollThumbPosition()
			{
				Win32.SCROLLINFO si = new Win32.SCROLLINFO();
				si.fMask = 0x10;
				bool r = Win32.GetScrollInfo(
					new HandleRef(_parent, _parent.Handle),
					this.Orientation, si);
				return si.nTrackPos;
			}
Exemple #3
0
            /// <summary>
            /// gets the position where the scroll thumb is released
            /// </summary>
            public int GetScrollThumbPosition()
            {
                Win32.SCROLLINFO si = new Win32.SCROLLINFO();
                si.fMask = 0x10;
                bool r = Win32.GetScrollInfo(
                    new HandleRef(_parent, _parent.Handle),
                    this.Orientation, si);

                return(si.nTrackPos);
            }
Exemple #4
0
 /// <summary>
 /// Позиция вертикального скролла
 /// </summary>
 internal static int GetVScrollPos(TextBoxBase richTextBox)
 {
     Win32.SCROLLINFO info = VScrollInfo(richTextBox, Win32.SIF_ALL);
     if (info.nTrackPos == 0)
     {
         if (richTextBox.GetCharIndexFromPosition(new Point(2, 2)) == 0)
         {
             return(0);
         }
         return(info.nPos);
     }
     return(info.nTrackPos);
 }
Exemple #5
0
        /// <summary>
        /// Позиция вертикального скролла
        /// </summary>
        internal static void SetVScrollPos(TextBoxBase richTextBox, int nPos)
        {
            Win32.SCROLLINFO info = new Win32.SCROLLINFO();
            info.cbSize = Marshal.SizeOf(info);
            info.fMask  = Win32.SIF_POS;
            info.nPos   = nPos;
            int oldPos = GetVScrollPos(richTextBox);

            Win32.SetScrollInfo(richTextBox.Handle, Win32.SB_VERT, ref info, true);
            int newPos = GetVScrollPos(richTextBox);

            IntPtr ptrWparam = new IntPtr(Win32.SB_THUMBTRACK + 0x10000 * newPos);
            IntPtr ptrLparam = new IntPtr(0);

            Win32.SendMessage(richTextBox.Handle, WM_VSCROLL, ptrWparam, ptrLparam);
        }
Exemple #6
0
			/// <summary>
			/// updates the data to the visual interface
			/// </summary>
			public void UpdateScrollInfo()
			{
				if (_parent.IsHandleCreated && _visible)
				{
					Win32.SCROLLINFO si = new Win32.SCROLLINFO();
					si.cbSize = Marshal.SizeOf(typeof(Win32.SCROLLINFO));
					si.fMask = 0x17;
					si.nMin = _minimum;
					si.nMax = _maximum;
					si.nPage = this.PageSize;
					si.nPos = _value;
					si.nTrackPos = 0;
					Win32.SetScrollInfo(
						new HandleRef(_parent, _parent.Handle),
						this.Orientation, si, true);
				}
			}
Exemple #7
0
 /// <summary>
 /// updates the data to the visual interface
 /// </summary>
 public void UpdateScrollInfo()
 {
     if (_parent.IsHandleCreated && _visible)
     {
         Win32.SCROLLINFO si = new Win32.SCROLLINFO();
         si.cbSize    = Marshal.SizeOf(typeof(Win32.SCROLLINFO));
         si.fMask     = 0x17;
         si.nMin      = _minimum;
         si.nMax      = _maximum;
         si.nPage     = this.PageSize;
         si.nPos      = _value;
         si.nTrackPos = 0;
         Win32.SetScrollInfo(
             new HandleRef(_parent, _parent.Handle),
             this.Orientation, si, true);
     }
 }
Exemple #8
0
 public static extern int SetScrollInfo(IntPtr hwnd, int bar, ref Win32.SCROLLINFO si, bool fRedraw);
Exemple #9
0
 public static extern int GetScrollInfo(IntPtr hWnd, int fnBar, ref Win32.SCROLLINFO info);
Exemple #10
0
        public void AddMessage(string log, string message)
        {
            RichTextBox box = FindLogWindow(log);
            HandleRef   hnd = new HandleRef(box, box.Handle);

            Win32.SCROLLINFO scrollinfo = new Win32.SCROLLINFO(Win32.SIF_RANGE | Win32.SIF_PAGE | Win32.SIF_POS);

            if (box.Visible)
            {
                Win32.SendMessage(hnd, Win32.WM_SETREDRAW, Win32.FALSE, 0);
            }

            // Remember the selection
            int selstart  = box.SelectionStart;
            int sellength = box.SelectionLength;

            // Remember where we were before adding the text
            int oldmaxpos, oldpos;

            Win32.GetScrollInfo(hnd, Win32.SB_VERT, ref scrollinfo);
            oldmaxpos = scrollinfo.nMax;
            oldpos    = scrollinfo.nPos;

            // Append the text
            box.AppendText(message);

            // Find out where we are now
            int minpos, maxpos, pagesize;

            Win32.GetScrollInfo(hnd, Win32.SB_VERT, ref scrollinfo);
            minpos   = scrollinfo.nMin;
            maxpos   = scrollinfo.nMax;
            pagesize = (int)scrollinfo.nPage;

            // Fix the selection (this breaks the scroll position!)
            if (selstart > 0)
            {
                box.SelectionStart = selstart;
            }
            if (sellength > 0)
            {
                box.SelectionLength = sellength;
            }

            // Fix the scroll position
            if (oldpos >= oldmaxpos - pagesize * 2)                   // Allow two extra lines leeway
            // Only scroll to bottom if we WERE at the max (before text was added)
            //Win32.SendMessage(box.Handle, Win32.EM_SETSCROLLPOS, 0, new Win32.POINT(0, maxpos - pagesize - 1));
            {
                Win32.RichTextBox_SetScrollPos(hnd, 0, maxpos - pagesize - 1);
            }
            else
            {
                // Return to same place we were in when text was added
                //Win32.SendMessage(box.Handle, Win32.EM_SETSCROLLPOS, 0, new Win32.POINT(0, oldpos));
                Win32.RichTextBox_SetScrollPos(hnd, 0, oldpos);
            }

            if (box.Visible)
            {
                Win32.SendMessage(hnd, Win32.WM_SETREDRAW, Win32.TRUE, 0);
                box.Invalidate();
            }
        }
Exemple #11
0
 /// <summary>
 /// Минимальная позиция вертикального скролла
 /// </summary>
 private static int VScrollPosMin(RichTextBox richTextBox)
 {
     Win32.SCROLLINFO info = VScrollInfo(richTextBox, Win32.SIF_RANGE);
     return(info.nMin);
 }