Rei*_*ica 35
您可以通过使用名为ScrollToCaret的函数来完成此操作.您需要先将插入位置设置到文本框的末尾,然后滚动到它.这是怎么做的:
//move the caret to the end of the text
textBox.SelectionStart = textBox.TextLength;
//scroll to the caret
textBox.ScrollToCaret();
Run Code Online (Sandbox Code Playgroud)
Jul*_*ian 27
这是一个古老的问题,但没有一个建议的答案对我有用(ScrollToCaret()仅在TextBox具有焦点时才有效).所以如果在某些时候还有更多人应该搜索这个,我想我会分享我发现的解决方案:
public class Utils
{
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern int SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam, IntPtr lParam);
private const int WM_VSCROLL = 0x115;
private const int SB_BOTTOM = 7;
/// <summary>
/// Scrolls the vertical scroll bar of a multi-line text box to the bottom.
/// </summary>
/// <param name="tb">The text box to scroll</param>
public static void ScrollToBottom(TextBox tb)
{
SendMessage(tb.Handle, WM_VSCROLL, (IntPtr)SB_BOTTOM, IntPtr.Zero);
}
}
Run Code Online (Sandbox Code Playgroud)
该解决方案应该归功于bytes.com上的这篇文章:http://bytes.com/topic/c-sharp/answers/248500-scroll-bottom-textbox#post1005377
归档时间: |
|
查看次数: |
38784 次 |
最近记录: |