本文整理汇总了C#中System.Windows.Forms.TreeView.GetNodeAt方法的典型用法代码示例。如果您正苦于以下问题:C# TreeView.GetNodeAt方法的具体用法?C# TreeView.GetNodeAt怎么用?C# TreeView.GetNodeAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.TreeView
的用法示例。
在下文中一共展示了TreeView.GetNodeAt方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetPositionToInsert
/// <summary>
/// Вычисляет место для вставки узла при перетаскивании
/// </summary>
/// <param name="tv">Дерево</param>
/// <param name="x">Экранные координаты курсора</param>
/// <param name="y">Экранные координаты курсора</param>
/// <param name="NewParent">Узел, являющийся новым родителем</param>
/// <param name="NewPos">Позиция среди подузлов этого родителя</param>
public static void GetPositionToInsert(TreeView tv, TreeViewAdapter tva, int x, int y, out TreeNode NewParent, out int NewPos)
{
Point pt = tv.PointToClient(new Point(x, y));
TreeNode DestinationNode = tv.GetNodeAt(pt);
if (DestinationNode == null)
{
NewParent = null;
NewPos = tv.Nodes.Count;
return;
}
int kind;
PointOfInterest pti = tva.GetPointByNode(DestinationNode);
bool NestingAllowed = pti != null;
int border = DestinationNode.Bounds.Height / 4;
if (pt.Y <= (DestinationNode.Bounds.Top + border))
kind = -1; //верхняя четверть - перед узлом
else if (pt.Y >= (DestinationNode.Bounds.Bottom - border))
{
if (!DestinationNode.IsExpanded)
kind = 1; //нижняя четверть неразвернутого узла - после узла
else
kind = 0; //нижняя четверть развернутого узла - внутрь
}
else
kind = 0; //Иначе - внутрь
if (kind == 0 && ! NestingAllowed)
if (pt.Y <= (DestinationNode.Bounds.Top + 2*border))
kind = -1; //если внутрь нельзя и верхняя половина - перед узлом
else
kind = 1; //Внутрь нельзя и нижняя половина - после узла
if (kind == -1)
{
//Перед узлом
NewParent = DestinationNode.Parent;
if (NewParent == null)
NewPos = tv.Nodes.IndexOf(DestinationNode);
else
NewPos = DestinationNode.Parent.Nodes.IndexOf(DestinationNode);
}
else if (kind == 1)
{
//После узла
NewParent = DestinationNode.Parent;
if (NewParent == null)
NewPos = tv.Nodes.IndexOf(DestinationNode) + 1;
else
NewPos = DestinationNode.Parent.Nodes.IndexOf(DestinationNode) + 1;
}
else
{
//Внутрь узла
NewParent = DestinationNode;
NewPos = DestinationNode.Nodes.Count;
}
}
示例2: InitTreeView
private void InitTreeView()
{
objTreeView = new TreeView();
objTreeView.ShowLines = true;
objTreeView.ShowNodeToolTips = true;
objTreeView.ShowPlusMinus = true;
objTreeView.ShowRootLines = true;
objTreeView.ImageList = imgList;
objTreeView.Dock = DockStyle.Fill;
objTreeView.AllowDrop = true;
objTreeView.DragDrop += new DragEventHandler(FileDragAndDropHandler.OnDragDrop);
objTreeView.DragEnter += new DragEventHandler(FileDragAndDropHandler.OnDragEnter);
objTreeView.MouseDown += delegate(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
objTreeView.SelectedNode = objTreeView.GetNodeAt(e.X, e.Y);
}
};
objTreeView.AfterSelect += new TreeViewEventHandler(OnAfterSelect);
objTreeView.AfterExpand += new TreeViewEventHandler(OnAfterExpand);
}
示例3: getTreeNodeAtDroppedOverPoint
public static TreeNode getTreeNodeAtDroppedOverPoint(TreeView tvTreeView, int iDroppedX, int iDroppedY)
{
Point pPointToString = tvTreeView.PointToScreen(tvTreeView.Location);
int iAdjustedX = tvTreeView.Left + iDroppedX - pPointToString.X;
int iAdjustedY = tvTreeView.Top + iDroppedY - pPointToString.Y;
//PublicDI.log.info("x:{0} y:{1} - {2}, {3}", x, y, tvCurrentFilters.Left, tvCurrentFilters.Top);
return tvTreeView.GetNodeAt(iAdjustedX, iAdjustedY);
}
示例4: TreeViewMouseUp
private void TreeViewMouseUp(TreeView treeView, System.Windows.Forms.MouseEventArgs e)
{
TreeNode onNode = treeView.GetNodeAt(new Point(e.X, e.Y));
if (onNode != null)
{
if (treeView.SelectedNode != onNode)
{
treeView.SelectedNode = onNode;
}
}
if (e.Button == MouseButtons.Right)
{
contextMenuObjects.Clear() ;
if (treeView.SelectedNode != null)
{
contextMenuObjects.Add(treeView.SelectedNode);
ShowContextMenu(treeView, e.X, e.Y);
}
}
}
示例5: TreeViewDragOver
private void TreeViewDragOver(TreeView treeView, System.Windows.Forms.DragEventArgs e)
{
if (insideTreeViewDragOver)
return;
insideTreeViewDragOver = true;
try
{
Point pt = treeView.PointToClient(new Point(e.X, e.Y));
int x = pt.X;
int y = pt.Y;
string data = "";
bool doHilite = false;
ObjectTreeNode overNode = (ObjectTreeNode) treeView.GetNodeAt(new Point(x, y));
if (e.Data.GetDataPresent(typeof(string)))
{
data = (string) e.Data.GetData(typeof(string));
}
if (data == null)
data = "";
if (data.Length > 0)
{
string header;
XmlNode payload = ParseDragData(data, out header);
if (header == "object")
{
if (overNode != null)
{
if (overNode.PropertyMap != null)
{
object dropObject = GetDropObject(payload);
IClassMap dropClassMap = Context.DomainMap.MustGetClassMap(dropObject.GetType() );
if (dropClassMap.IsSubClassOrThisClass(overNode.PropertyMap.GetReferencedClassMap()))
{
doHilite = true ;
}
}
}
}
}
if (doHilite)
{
e.Effect = DragDropEffects.Copy;
TurnOnTreeDragHilite(overNode);
}
else
TurnOffTreeDragHilite();
}
catch (Exception ex)
{
throw ex;
}
finally
{
insideTreeViewDragOver = false;
}
}
示例6: TreeViewDragDrop
private void TreeViewDragDrop(TreeView treeView, System.Windows.Forms.DragEventArgs e)
{
Point pt = treeView.PointToClient(new Point(e.X, e.Y));
int x = pt.X;
int y = pt.Y;
string data = "";
ObjectTreeNode overNode = (ObjectTreeNode) treeView.GetNodeAt(new Point(x, y));
if (e.Data.GetDataPresent(typeof(string)))
{
data = (string) e.Data.GetData(typeof(string));
}
if (data == null)
data = "";
if (data.Length > 0)
{
string header ;
XmlNode payload = ParseDragData(data, out header);
if (header == "object")
{
object dropObject = GetDropObject(payload);
if (overNode != null)
{
if (overNode.PropertyMap != null)
{
if (dropObject != null)
{
IClassMap dropClassMap = Context.DomainMap.MustGetClassMap(dropObject.GetType() );
if (dropClassMap.IsSubClassOrThisClass(overNode.PropertyMap.GetReferencedClassMap()))
{
if (overNode.PropertyMap.IsCollection)
{
IList list = (IList) Context.ObjectManager.GetPropertyValue(overNode.Obj, overNode.PropertyMap.Name);
list.Add(dropObject);
Context.ObjectManager.SetPropertyValue(overNode.Obj, overNode.PropertyMap.Name, list);
}
else
{
overNode.Obj.GetType().GetProperty(overNode.PropertyMap.Name).SetValue(overNode.Obj, dropObject, null);
}
RefreshAll();
}
}
}
}
else
{
if (dropObject != null)
{
OpenObject(dropObject);
}
}
}
}
TurnOffTreeDragHilite();
}
示例7: ShowContext
//////////////////////////////////////////////////////////////////////////
/// <summary>
/// Open a context menu at the right position on a tree view.
/// </summary>
/// <param name="tree">The tree view.</param>
/// <param name="contextMenu">The context menu to display.</param>
/// <param name="evt">The mouse event.</param>
/// <param name="mousePoint">The position of the mouse.</param>
//////////////////////////////////////////////////////////////////////////
public static void ShowContext(TreeView treeView, ContextMenuStrip contextMenu, MouseEventArgs evt, Point mousePoint)
{
// Retrieve the node under the mouse
treeView.SelectedNode = treeView.GetNodeAt(evt.X, evt.Y);
if (treeView.SelectedNode != null)
{
// Show context menu at correct position
contextMenu.Show(mousePoint);
}
}
示例8: favList_NodeMouseClick
private void favList_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
focusedTreeView = e.Node.TreeView;
if (e.Button == MouseButtons.Right)
{
focusedTreeView.SelectedNode = focusedTreeView.GetNodeAt(e.X, e.Y);
contextMenuStrip2.Show(focusedTreeView, e.Location);
}
}
示例9: Drop
private void Drop(TreeView treeView, DragEventArgs e)
{
FileBrowser fileBrowser = ((FileBrowser)(((KryptonGroupBox)(((Panel)treeView.Parent).Parent)).Parent));
TreeNode newNode;
if (e.Data.GetDataPresent("System.Windows.Forms.TreeNode", false))
{
Point pt = treeView.PointToClient(new Point(e.X, e.Y));
TreeNode destinationNode = treeView.GetNodeAt(pt);
newNode = (TreeNode)e.Data.GetData("System.Windows.Forms.TreeNode");
_PreviousNodeName = newNode.Text.Split(new string[] { "." }, StringSplitOptions.None)[0];
_SourcePath = newNode.FullPath;
if (destinationNode.ImageIndex == 2)
{
if (destinationNode.Parent.FullPath == newNode.Parent.FullPath)
_TargetPath = _SourcePath;
else if (File.Exists(destinationNode.Parent.FullPath + "\\" + newNode.Text.Split(new string[] { "." }, StringSplitOptions.None)[0] + ".xml"))
_TargetPath = destinationNode.Parent.FullPath + "\\" + newNode.Text.Split(new string[] { "." }, StringSplitOptions.None)[0] + "-COPY.xml";
else _TargetPath = destinationNode.Parent.FullPath + "\\" + newNode.Text.Split(new string[] { "." }, StringSplitOptions.None)[0] + ".xml";
}
else
{
if (File.Exists(destinationNode.FullPath + "\\" + newNode.Text.Split(new string[] { "." }, StringSplitOptions.None)[0] + ".xml"))
_TargetPath = destinationNode.FullPath + "\\" + newNode.Text.Split(new string[] { "." }, StringSplitOptions.None)[0] + "-COPY.xml";
else _TargetPath = destinationNode.FullPath + "\\" + newNode.Text.Split(new string[] { "." }, StringSplitOptions.None)[0] + ".xml";
}
if (_TargetPath != _SourcePath)
{
try
{
if (treeView.SelectedNode.ImageIndex == 2)
{
File.Move(_SourcePath, _TargetPath);
// Check if config in db exists, else add config
try
{
AnalyticsWebService.AnalyticsSoapClient session = new AnalyticsWebService.AnalyticsSoapClient();
int idConfig = session.Get_histo_id_config(_SourcePath);
if (idConfig == 0)
session.Add_histo_config(_PreviousNodeName.Replace(".xml", ""), _SourcePath);
session.Close();
}
catch { }
// Update Config path in database
try
{
AnalyticsWebService.AnalyticsSoapClient service = new AnalyticsWebService.AnalyticsSoapClient();
service.Update_histo_config_path(_SourcePath, _TargetPath);
service.Close();
}
catch { }
}
else if (treeView.SelectedNode.ImageIndex == 1)
Directory.Move(_SourcePath, _TargetPath.Replace(".xml", ""));
}
catch (Exception ex) { Console.WriteLine(ex); }
}
}
fileBrowser.EditToolStripMenuItem.Enabled = false;
EditToolStripButton.Enabled = false;
fileBrowser.PopulateTreeView();
}
示例10: TreeViewMouseUp
private void TreeViewMouseUp(TreeView treeView, MouseEventArgs e)
{
TreeNode onNode = treeView.GetNodeAt(new Point(e.X, e.Y));
if (onNode != null)
{
if (treeView.SelectedNode != onNode)
treeView.SelectedNode = onNode;
if (e.Button == MouseButtons.Right)
{
NodeBase nodeBase = onNode as NodeBase;
selected = nodeBase.Object;
if (onNode is AspectNode)
aspectContextMenuStrip.Show(treeView, new Point(e.X, e.Y));
if (onNode is AspectTargetNode)
aspectTargetContextMenuStrip.Show(treeView, new Point(e.X, e.Y));
if (onNode is MixinNode)
mixinContextMenuStrip.Show(treeView, new Point(e.X, e.Y));
if (onNode is PointcutNode)
pointcutContextMenuStrip.Show(treeView, new Point(e.X, e.Y));
if (onNode is PointcutTargetNode)
pointcutTargetContextMenuStrip.Show(treeView, new Point(e.X, e.Y));
if (onNode is InterceptorNode)
interceptorContextMenuStrip.Show(treeView, new Point(e.X, e.Y));
if (onNode is AssemblyNode)
assemblyContextMenuStrip.Show(treeView, new Point(e.X, e.Y));
}
}
else
{
selected = null;
}
}
示例11: TreeViewDragOver
private void TreeViewDragOver(TreeView treeView, DragEventArgs e)
{
if (insideTreeViewDragOver)
return;
insideTreeViewDragOver = true;
try
{
Point pt = treeView.PointToClient(new Point(e.X, e.Y));
int x = pt.X;
int y = pt.Y;
string data = "";
bool doHilite = false;
NodeBase overNode = (NodeBase)treeView.GetNodeAt(new Point(x, y));
if (e.Data.GetDataPresent(typeof(string)))
{
data = (string)e.Data.GetData(typeof(string));
}
if (data == null)
data = "";
if (data.Length > 0)
{
string header;
XmlNode payload = ParseDragData(data, out header);
if (header == "aspect")
{
if (overNode != null)
{
if (overNode is TypeNode)
{
doHilite = true;
}
}
}
if (header == "pointcut" || header == "interceptor")
{
if (overNode != null)
{
if (overNode is TypeNode)
{
doHilite = true;
}
if (overNode is MethodNode)
{
if (((MethodNode) overNode).CanBeProxied())
doHilite = true;
}
}
}
}
if (doHilite)
{
e.Effect = DragDropEffects.Copy;
TurnOnTreeDragHilite(overNode);
}
else
TurnOffTreeDragHilite();
}
catch (Exception ex)
{
throw ex;
}
finally
{
insideTreeViewDragOver = false;
}
}
示例12: TreeViewDragDrop
private void TreeViewDragDrop(TreeView treeView, DragEventArgs e)
{
Point pt = treeView.PointToClient(new Point(e.X, e.Y));
int x = pt.X;
int y = pt.Y;
string data = "";
NodeBase overNode = (NodeBase)treeView.GetNodeAt(new Point(x, y));
if (e.Data.GetDataPresent(typeof(string)))
{
data = (string)e.Data.GetData(typeof(string));
}
if (data == null)
data = "";
if (data.Length > 0)
{
string header;
XmlNode payload = ParseDragData(data, out header);
if (header == "aspect")
{
PresentationAspect dropAspect = GetDropAspect(payload);
if (overNode != null)
{
if (overNode is TypeNode)
{
if (dropAspect != null)
{
dropAspect.AddTypeTarget(((TypeNode)overNode).Type);
RefreshAll();
}
}
}
}
if (header == "pointcut")
{
PresentationPointcut dropPointcut = GetDropPointcut(payload);
if (overNode != null)
{
if (overNode is TypeNode)
{
if (dropPointcut != null)
{
dropPointcut.AddTypeTarget(((TypeNode)overNode).Type);
RefreshAll();
}
}
if (overNode is MethodNode)
{
if (dropPointcut != null)
{
MethodNode methodNode = overNode as MethodNode;
if (methodNode.CanBeProxied())
{
dropPointcut.AddMethodTarget(methodNode.MethodBase, methodNode.Type);
RefreshAll();
}
}
}
}
}
if (header == "interceptor")
{
PresentationInterceptor dropInterceptor = GetDropInterceptor(payload);
if (overNode != null)
{
if (overNode is TypeNode)
{
if (dropInterceptor != null)
{
dropInterceptor.AddTypeTarget(((TypeNode)overNode).Type);
RefreshAll();
}
}
if (overNode is MethodNode)
{
if (dropInterceptor != null)
{
MethodNode methodNode = overNode as MethodNode;
if (methodNode.CanBeProxied())
{
dropInterceptor.AddMethodTarget(methodNode.MethodBase, methodNode.Type);
RefreshAll();
}
}
}
}
}
}
TurnOffTreeDragHilite();
}
示例13: Smarttree
public Smarttree(TreeView tView)
{
this.tViewCut = tView;
root = tViewCut.GetNodeAt(0, 0);
}
示例14: GetCursorKind
/// <summary>
/// Возвращает номер курсора, который нужно показать в данной точке
/// </summary>
/// <param name="tv">TreeView, надо которым перемещается узел</param>
/// <param name="node">Перемещаемый узел</param>
/// <param name="x">Координаты курсора</param>
/// <param name="y">Координаты курсора</param>
/// <returns>-1 - обычный курсор, перемещать в эту точку нельзя
/// 0 - курсор, указывающий на добавление нового уровня
/// 1 - курсор, указывающий на добавление узла на том же уровне</returns>
public static int GetCursorKind(TreeView tv, TreeViewAdapter tva, TreeNode node, int x, int y)
{
TreeNode Dst;
int pos;
CursorHelper.GetPositionToInsert(tv, tva, x, y, out Dst, out pos);
if (!CursorHelper.NestingAllowed(node, Dst)// нельзя перемещать узел в своего же потомка
|| (Dst == node.Parent && (node.Index == pos || node.Index == pos - 1))// не надо двигать, если положение и так совпадет
)
return -1;
if (Dst != null && Dst == tv.GetNodeAt(tv.PointToClient(new Point(x, y))))
return 0;
else
return 1;
}