本文整理汇总了C#中System.Windows.Forms.TreeView.PointToClient方法的典型用法代码示例。如果您正苦于以下问题:C# TreeView.PointToClient方法的具体用法?C# TreeView.PointToClient怎么用?C# TreeView.PointToClient使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.TreeView
的用法示例。
在下文中一共展示了TreeView.PointToClient方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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;
}
}
示例3: 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();
}
示例4: 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();
}
示例5: 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;
}
}
示例6: 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();
}
示例7: 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;
}