我有一个固定大小的树形视图。我怎样才能让它滚动到水平和垂直?当我将Scrollable设置为true时,它只添加垂直滚动条,当滚动条到达表单底部时,剩下的文本不会滚动。请帮助我。如何在treeview中进行垂直和水平滚动?
P.S对不起英文不好
我有一个固定大小的树形视图。我怎样才能让它滚动到水平和垂直?当我将Scrollable设置为true时,它只添加垂直滚动条,当滚动条到达表单底部时,剩下的文本不会滚动。请帮助我。如何在treeview中进行垂直和水平滚动?
P.S对不起英文不好
你可以试试这个方法
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);
你能解释你的代码吗? – Vahan 2011-06-12 08:38:52
什么结束了实效F或者我正在修理[keyboardP]的代码片段:
myTreeView.Nodes[myTreeView.Nodes.Count - 1].EnsureVisible();
presto。单杠。
你的意思是你不能一直滚动到最后一个'treeview节点'?你是否动态添加项目? – keyboardP 2011-06-06 15:31:25
是的,如果三视图中有很多节点,那么我无法达到最后。不,我不添加dinamicaly,我将数据库名称和表名从sql加载到treeview。 – Vahan 2011-06-06 15:39:15
有点破解,但看看它是否有效。添加节点后,添加如下内容:'myTreeView.Nodes.Item [myTreeView.Nodes.Count - 1] .EnsureVisible()' – keyboardP 2011-06-06 15:58:11