2011-06-06 38 views
1

我有一個固定大小的樹形視圖。我怎樣才能讓它滾動到水平和垂直?當我將Scrollable設置爲true時,它只添加垂直滾動條,當滾動條到達表單底部時,剩下的文本不會滾動。請幫助我。如何在treeview中進行垂直和水平滾動?

P.S對不起英文不好

+0

你的意思是你不能一直滾動到最後一個'treeview節點'?你是否動態添加項目? – keyboardP 2011-06-06 15:31:25

+0

是的,如果三視圖中有很多節點,那麼我無法達到最後。不,我不添加dinamicaly,我將數據庫名稱和表名從sql加載到treeview。 – Vahan 2011-06-06 15:39:15

+0

有點破解,但看看它是否有效。添加節點後,添加如下內容:'myTreeView.Nodes.Item [myTreeView.Nodes.Count - 1] .EnsureVisible()' – keyboardP 2011-06-06 15:58:11

回答

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); 
+0

你能解釋你的代碼嗎? – Vahan 2011-06-12 08:38:52

0

什麼結束了實效F或者我正在修理[keyboardP]的代碼片段:

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

presto。單槓。