如何在树视图中进行垂直和水平滚动?

时间:2011-06-06 14:54:46

标签: c# winforms treeview scroll

我有一个固定大小的树视图。如何将其滚动到水平和垂直?当我将Scrollable设置为true时,它只添加垂直滚动,当滚动到达表单底部并且还有文本剩余时滚动没有下降。请帮助我。

p.s抱歉英语不好

2 个答案:

答案 0 :(得分:1)

您可以尝试这种方法

private const int WM_SCROLL = 276; // Horizontal scroll
private const int WM_VSCROLL = 277; // Vertical scroll
private const int SB_LINEUP = 0; // Scrolls one line up
private const int SB_LINELEFT = 0;// Scrolls one cell left
private const int SB_LINEDOWN = 1; // Scrolls one line down
private const int SB_LINERIGHT = 1;// Scrolls one cell right
private const int SB_PAGEUP = 2; // Scrolls one page up
private const int SB_PAGELEFT = 2;// Scrolls one page left
private const int SB_PAGEDOWN = 3; // Scrolls one page down
private const int SB_PAGERIGTH = 3; // Scrolls one page right
private const int SB_PAGETOP = 6; // Scrolls to the upper left
private const int SB_LEFT = 6; // Scrolls to the left
private const int SB_PAGEBOTTOM = 7; // Scrolls to the upper right
private const int SB_RIGHT = 7; // Scrolls to the right
private const int SB_ENDSCROLL = 8; // Ends scroll

[DllImport("user32.dll",CharSet=CharSet.Auto)]
private static extern int SendMessage(IntPtr hWnd, int wMsg,IntPtr wParam, IntPtr lParam);

SendMessage(treeView.Handle, WM Scroll Message, (IntPtr) Scroll Command ,IntPtr.Zero);

向上滚动

SendMessage(treeView.Handle, WM_VSCROLL,(IntPtr)SB_PAGEUP,IntPtr.Zero);

向下滚动页面

 SendMessage(treeView.Handle, WM_VSCROLL,(IntPtr)SB_PAGEDOWN,IntPtr.Zero);

答案 1 :(得分:0)

最终为我工作的是修复[keyboardP]的代码片段:

myTreeView.Nodes[myTreeView.Nodes.Count - 1].EnsureVisible();

似的。单杠。