hsluoyz
hsluoyz

Reputation: 2889

How to make a CTreeCtrl item centrally displayed?

I know that the function EnsureVisible(HTREEITEM hItem) can show hItem by scrolling the bar of the CTreeCtrl control. But sometimes the hItem is displayed either beside the top or beside the bottom of the control, which is so unfriendly for users. I want the item to be shown in the middle of the control. Any good solutions?

Upvotes: 1

Views: 665

Answers (1)

Remy Lebeau
Remy Lebeau

Reputation: 595392

You would have to scroll the CTreeCtrl manually. Call CTreeCtrl::EnsureVisible() to make the item visible, then call CTreeCtrl::GetItemRect() to retrieve the item's current coordinates, and then call CWnd::ScrollWindow/Ex() specifying the necessary offset to put the item wherever you want it.

Upvotes: 4

Related Questions