/// <include file='doc\LanguageService.uex' path='docs/doc[@for="LanguageService.ScrollToEnd2"]/*' /> public void ScrollToEnd(IVsTextView view) { IVsTextLines buffer; NativeMethods.ThrowOnFailure(view.GetBuffer(out buffer)); int lines; NativeMethods.ThrowOnFailure(buffer.GetLineCount(out lines)); int lineHeight; NativeMethods.ThrowOnFailure(view.GetLineHeight(out lineHeight)); Microsoft.VisualStudio.NativeMethods.RECT bounds = new Microsoft.VisualStudio.NativeMethods.RECT(); NativeMethods.GetClientRect(view.GetWindowHandle(), ref bounds); int visibleLines = ((bounds.bottom - bounds.top) / lineHeight) - 1; int top = Math.Max(0, lines - visibleLines + 4); NativeMethods.ThrowOnFailure(view.SetTopLine(top)); }
/// <include file='doc\LanguageService.uex' path='docs/doc[@for="LanguageService.ScrollToEnd2"]/*' /> public void ScrollToEnd(IVsTextView view) { IVsTextLines buffer; NativeMethods.ThrowOnFailure(view.GetBuffer(out buffer)); int lines; NativeMethods.ThrowOnFailure(buffer.GetLineCount(out lines)); int lineHeight; NativeMethods.ThrowOnFailure(view.GetLineHeight(out lineHeight)); Microsoft.VisualStudio.NativeMethods.RECT bounds = new Microsoft.VisualStudio.NativeMethods.RECT(); NativeMethods.GetClientRect(view.GetWindowHandle(), ref bounds); int visibleLines = ((bounds.bottom - bounds.top) / lineHeight) - 1; // If the view hasn't been shown yet, the bounds will be empty, yielding -1 for visibleLinse. if (visibleLines < 0) { visibleLines = 0; } // The line number needed to be passed to SetTopLine is ZERO based, so need to subtract ONE from number of total lines int top = Math.Max(0, lines - visibleLines - 1); Debug.Assert(lines > top, "Cannot set top line to be greater than total number of lines"); NativeMethods.ThrowOnFailure(view.SetTopLine(top)); }