attach a panel to TreeView control

被刻印的时光 ゝ 提交于 2019-12-11 18:41:23

问题


I am beginner in c#. In my project, I populated a xml file inside a TreeView control. If the xml file is large, the TreeView control is showing the data with scroll bars. Beside this, whenever the user double clicks a node I am showing a panel beside the selected node something like this..

When I scroll the TreeView Control :

My question is how to make the panel attached to treeView control so that eventhough the user scrolls the TreeView control the panel should also move along with the selected node.


回答1:


Well, hard to do since TreeView doesn't have a Scroll event. It isn't reliable anyway since nodes can be expanded and collapsed, changing the position and visibility of the node. The backup plan is to use a Timer. This worked well:

    private void timer1_Tick(object sender, EventArgs e) {
        var node = treeView1.SelectedNode;
        if (node == null || !node.IsVisible) panel1.Visible = false;
        else {
            panel1.Visible = true;
            var nodepos = treeView1.PointToScreen(node.Bounds.Location);
            var panelpos = panel1.Parent.PointToClient(nodepos);
            panel1.Top = panelpos.Y;
        }
    }


来源:https://stackoverflow.com/questions/13091200/attach-a-panel-to-treeview-control

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!