C#实现listBox滚动到最后一行且不选中

利用windows API中的SendMessage来实现,看具体代码和注释把

[DllImport("User32.dll")]
private static extern Int32 SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
/*
 WM_VSCROLL 定义在头文件Winuser.h中。定义为:#define WM_VSCROLL 0x0115.
 当窗口的标准垂直滚动条中有滚动的事件发生时,在我们的窗口应用程序的消息队列中将产生一条WM_VSCROLL消息
 */
public const int WM_VSCROLL = 0x0115;//垂直滚动条消息
public const int SB_LINEDOWN = 1;//向下滚动一行
public const int SB_PAGEDOWN = 3;//向下滚动一页
public const int SB_BOTTOM = 7;//滚动到最底部
/// <summary>
/// 调用该方法执行滚动
/// </summary>
public void toListBoxEnd() 
{
    SendMessage(listBox1.Handle, WM_VSCROLL, SB_BOTTOM, 0);
}

DllImport需要引入命名空间

using System.Runtime.InteropServices;

有兴趣的朋友还可以试一下对ListView是否有效