您的位置:首页 > 编程语言 > C#

C# TreeView实现拖动节点时滚动条自动滚动

2010-03-27 22:13 483 查看
You need to call the Windows API SendMessage() function.

//using System.Runtime.InteropServices;

[DllImport("user32.dll")]

private static extern int SendMessage(IntPtr hWnd, int wMsg, int wParam, int lParam);

private void treeView1_DragOver(object sender, DragEventArgs e)
{
// Set a constant to define the autoscroll region
const Single scrollRegion = 20;

// See where the cursor is
Point pt = treeView1.PointToClient(Cursor.Position);

// See if we need to scroll up or down
if ((pt.Y + scrollRegion) > treeView1.Height)
{
// Call the API to scroll down
SendMessage(treeView1.Handle, (int)277, (int)1, 0);
}
else if (pt.Y < (treeView1.Top + scrollRegion))
{
// Call thje API to scroll up
SendMessage(treeView1.Handle, (int)277, (int)0, 0);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: