简体   繁体   中英

attach a panel to TreeView control

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.

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;
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM