简体   繁体   English

将面板附加到TreeView控件

[英]attach a panel to TreeView control

I am beginner in c#. 我是c#的初学者。 In my project, I populated a xml file inside a TreeView control. 在我的项目中,我在TreeView控件中填充了一个xml文件。 If the xml file is large, the TreeView control is showing the data with scroll bars. 如果xml文件很大, TreeView控件将显示带滚动条的数据。 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 : 当我滚动TreeView控件时

在此输入图像描述

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. 我的问题是如何使panel附加到treeView控件,以便用户滚动TreeView控件时面板也应该与所选节点一起移动。

Well, hard to do since TreeView doesn't have a Scroll event. 好吧,很难做到,因为TreeView没有Scroll事件。 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. 备份计划是使用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;
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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