当前位置: 首页>>代码示例>>C#>>正文


C# TreeView.PointToClient方法代码示例

本文整理汇总了C#中TreeView.PointToClient方法的典型用法代码示例。如果您正苦于以下问题:C# TreeView.PointToClient方法的具体用法?C# TreeView.PointToClient怎么用?C# TreeView.PointToClient使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TreeView的用法示例。


在下文中一共展示了TreeView.PointToClient方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SolutionBrowserControl

    public SolutionBrowserControl()
    {
        #region Image list
        int iconSize = 16;
        ImageList imageList = new ImageList() {
            ColorDepth = ColorDepth.Depth32Bit,
            ImageSize = new Size(iconSize, iconSize)
        };

        imageList.Images.Add("folder", Icons.GetBitmap("solutionexplorer.folder", iconSize));
        imageList.Images.Add("folderOpen", Icons.GetBitmap("solutionexplorer.folderOpen", iconSize));
        imageList.Images.Add("asm", Icons.GetBitmap("filetype.asm", iconSize));
        imageList.Images.Add("c", Icons.GetBitmap("filetype.c", iconSize));
        imageList.Images.Add("cpp", Icons.GetBitmap("filetype.cpp", iconSize));
        imageList.Images.Add("h", Icons.GetBitmap("filetype.h", iconSize));
        imageList.Images.Add("vb", Icons.GetBitmap("filetype.vb", iconSize));
        imageList.Images.Add("cs", Icons.GetBitmap("filetype.cs", iconSize));
        imageList.Images.Add("unknown", Icons.GetBitmap("filetype.unknown", iconSize));

        imageList.Images.Add("solution", Icons.GetBitmap("solutionexplorer.solution", iconSize));
        imageList.Images.Add("proj", Icons.GetBitmap("solutionexplorer.project", iconSize));
        #endregion

        #region Tree view
        p_Tree = new TreeView() {
            Dock = DockStyle.Fill,
            ImageList = imageList,
            LabelEdit = true,

            AllowDrop = true
        };
        Controls.Add(p_Tree);

        /*Drag drop*/
        p_Tree.ItemDrag += tree_itemDrag;
        p_Tree.DragEnter += tree_dragEnter;
        p_Tree.DragOver += tree_dragOver;
        p_Tree.DragDrop += tree_dragDrop;

        /*When the user hit's enter, make whatever is selected in
          the tree list expand.*/
        p_Tree.KeyDown += delegate(object s, KeyEventArgs e) {
            if (e.KeyCode != Keys.Enter) { return; }
            TreeNode selected = p_Tree.SelectedNode;
            if (selected == null) { return; }
            selected.Expand();

            //open the file?
            if (selected.Tag is ProjectFile && FileOpened != null) {
                FileOpened(this, (ProjectFile)selected.Tag);
            }
        };

        /*When the user double clicks on a file, open it*/
        p_Tree.DoubleClick += delegate(object s, EventArgs e) {
            Point cursorPosition = Cursor.Position;
            cursorPosition = p_Tree.PointToClient(cursorPosition);
            TreeNode node = p_Tree.GetNodeAt(cursorPosition);
            if (node == null || !(node.Tag is ProjectFile)) { return; }
            if (FileOpened != null) {
                FileOpened(this, (ProjectFile)node.Tag);
            }
        };

        /*Make sure that left/right click causes the appropriate node
          to be selected*/
        p_Tree.MouseDown += delegate(object s, MouseEventArgs e) {
            TreeNode selected = p_Tree.GetNodeAt(e.X, e.Y);
            if (selected == null) { return; }
            p_Tree.SelectedNode = selected;
        };

        /*When a folder is expanded, change the icon to an expanded
         folde*/
        p_Tree.AfterCollapse += delegate(object sender, TreeViewEventArgs e) {
            if (!(e.Node.Tag is ProjectDirectory)) { return; }
            e.Node.ImageKey = e.Node.SelectedImageKey = "folder";
        };
        p_Tree.AfterExpand += delegate(object sender, TreeViewEventArgs e) {
            if (!(e.Node.Tag is ProjectDirectory)) { return; }
            e.Node.ImageKey = e.Node.SelectedImageKey = "folderOpen";
        };
        #endregion

        #region Tree right click
        ContextMenuStrip rightClick = new ContextMenuStrip();
        rightClick.Opening += delegate(object s, System.ComponentModel.CancelEventArgs e) {
            presentRightClickMenu(rightClick);
            e.Cancel = rightClick.Items.Count == 0;
        };
        p_Tree.ContextMenuStrip = rightClick;
        #endregion
    }
开发者ID:TomWilsonCoder,项目名称:oside,代码行数:93,代码来源:SolutionBrowser.cs


注:本文中的TreeView.PointToClient方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。