/// <summary> /// Sets the scoll position of the text box. /// </summary> /// <remarks>This code compensates for the EM_GETSCROLLPOS message limitations.</remarks> /// <param name="value">The new scroll position.</param> protected void SetScrollPos(Point value) { // Save the original value EnhTextBoxAPIFunctions.POINTAPI lpOriginal = (EnhTextBoxAPIFunctions.POINTAPI)value; if (lpOriginal.Y < 0) { lpOriginal.Y = 0; } if (lpOriginal.X < 0) { lpOriginal.X = 0; } // Default factored value to original value with Y Factor compensation EnhTextBoxAPIFunctions.POINTAPI lpFactored = (EnhTextBoxAPIFunctions.POINTAPI)value; lpFactored.Y = (int)((double)lpOriginal.Y * mdScrollPosYfactor); // Current result EnhTextBoxAPIFunctions.POINTAPI lpResult = (EnhTextBoxAPIFunctions.POINTAPI)value; EnhTextBoxAPIFunctions.SendMessagePoint(this.Handle, EnhTextBoxAPIFunctions.Messages.EM_SETSCROLLPOS, 0, ref lpFactored); EnhTextBoxAPIFunctions.SendMessagePoint(this.Handle, EnhTextBoxAPIFunctions.Messages.EM_GETSCROLLPOS, 0, ref lpResult); int liLoopCount = 0; int liMaxLoop = 100; while (lpResult.Y != lpOriginal.Y) { // Adjust the input. if (lpResult.Y > lpOriginal.Y) { lpFactored.Y -= (lpResult.Y - lpOriginal.Y) / 2 - 1; } else if (lpResult.Y < lpOriginal.Y) { lpFactored.Y += (lpOriginal.Y - lpResult.Y) / 2 + 1; } // test the new input. EnhTextBoxAPIFunctions.SendMessagePoint(this.Handle, EnhTextBoxAPIFunctions.Messages.EM_SETSCROLLPOS, 0, ref lpFactored); EnhTextBoxAPIFunctions.SendMessagePoint(this.Handle, EnhTextBoxAPIFunctions.Messages.EM_GETSCROLLPOS, 0, ref lpResult); // save new factor, test for exit. liLoopCount++; if (liLoopCount >= liMaxLoop || lpResult.Y == lpOriginal.Y) { mdScrollPosYfactor = (double)lpFactored.Y / (double)lpOriginal.Y; break; } } }
/// <summary> /// Gets the scroll position of the text box. /// </summary> /// <returns>The point denoting the scroll position.</returns> protected Point GetScrollPos() { EnhTextBoxAPIFunctions.POINTAPI lpScrollPoint = new EnhTextBoxAPIFunctions.POINTAPI(); EnhTextBoxAPIFunctions.SendMessagePoint(this.Handle, EnhTextBoxAPIFunctions.Messages.EM_GETSCROLLPOS, 0, ref lpScrollPoint); return(new Point(lpScrollPoint.X, lpScrollPoint.Y)); }