本文整理汇总了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
}