本文整理汇总了C#中System.Windows.Forms.TreeNode.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# TreeNode.Clone方法的具体用法?C# TreeNode.Clone怎么用?C# TreeNode.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.TreeNode
的用法示例。
在下文中一共展示了TreeNode.Clone方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadProjectsAndBuilds
public void LoadProjectsAndBuilds(string teamCityServerUrl)
{
_teamCityAdapter.InitializeHttpClient(teamCityServerUrl);
var projects = _teamCityAdapter.GetAllProjects();
var loadingNode = new TreeNode("loading...");
treeViewTeamCityProjects.Nodes.Clear();
treeViewTeamCityProjects.Nodes.AddRange(projects.Select(p => new TreeNode(p)
{
Name = p,
Tag = new Node {IsProject = true, Loaded = false, Name = p}
}).OrderBy(p=>p.Name).ToArray());
foreach (TreeNode node in treeViewTeamCityProjects.Nodes)
{
node.Nodes.Add((TreeNode) loadingNode.Clone());
}
if(!string.IsNullOrWhiteSpace(TeamCityProjectName))
{
foreach (TreeNode node in treeViewTeamCityProjects.Nodes)
{
if(node.Name == TeamCityProjectName)
{
treeViewTeamCityProjects.SelectedNode = node;
node.Expand();
break;
}
}
}
}
示例2: CloneTreeNode
public static TreeNode CloneTreeNode(TreeNode tn)
{
if (tn == null)
return null;
TreeNode res = (TreeNode)tn.Clone();
CloneTags(res);
return res;
}
示例3: FolderSelector
public FolderSelector(TreeView Source, TreeNode Node)
{
InitializeComponent();
treeView1.SetExplorerTheme();
treeView1.ImageList = Source.ImageList;
TreeNode NewNode = (TreeNode)Node.Clone();
treeView1.Nodes.Add(NewNode);
NewNode.Expand();
}
示例4: LoadProjects
public void LoadProjects(string teamCityServerUrl)
{
_teamCityAdapter.InitializeHttpClient(teamCityServerUrl);
var projects = _teamCityAdapter.GetAllProjects();
var loadingNode = new TreeNode("loading...");
treeViewTeamCityProjects.Nodes.Clear();
treeViewTeamCityProjects.Nodes.AddRange(projects.Select(p => new TreeNode(p)
{
Tag = new Node {IsProject = true, Loaded = false, Name = p},
}).ToArray());
foreach (TreeNode node in treeViewTeamCityProjects.Nodes)
{
node.Nodes.Add((TreeNode) loadingNode.Clone());
}
}
示例5: btnBrowse_Click
private void btnBrowse_Click(object sender, EventArgs e)
{
TreeNode _nodeTemp = new TreeNode();
OpenFileDialog dlg = new OpenFileDialog();
dlg.DefaultExt = "CSS";
dlg.Filter = "Cascading Style Sheet (*.css)|*.css";
if (dlg.ShowDialog() == DialogResult.OK)
{
string path = dlg.FileName;
var ctp = new CssTreeParser();
try
{
ctp.Parse(path);
}
catch (Exception)
{
throw;
}
CommonTree r = ctp.Root;
_nodeTemp.Nodes.Clear();
if (r.Text != "nil" && r.Text != null)
{
_nodeTemp.Text = "nil";
AddSubTree(_nodeTemp, r, ctp);
}
else
{
string rootNode = r.Text ?? "nil";
_nodeTemp.Text = rootNode;
foreach (CommonTree child in ctp.Children(r))
{
AddSubTree(_nodeTemp, child, ctp);
}
}
}
treeView1.Nodes.Clear();
treeView1.Nodes.Add((TreeNode)_nodeTemp.Clone());
treeView1.ExpandAll();
}
示例6: ExpectedInhertitParentClassPropertyTree
public void ExpectedInhertitParentClassPropertyTree()
{
expectedIPCPNode.Nodes.Clear();
var tree = new TreeNode();
tree.Text = "ROOT";
tree.Nodes.Add("RULE");
tree.Nodes[0].Nodes.Add("CLASS");
tree.Nodes[0].Nodes[0].Nodes.Add("letter");
tree.Nodes[0].Nodes.Add("PROPERTY");
tree.Nodes[0].Nodes[1].Nodes.Add("text-align");
tree.Nodes[0].Nodes[1].Nodes.Add("center");
tree.Nodes[0].Nodes.Add("PROPERTY");
tree.Nodes[0].Nodes[2].Nodes.Add("font-style");
tree.Nodes[0].Nodes[2].Nodes.Add("italic");
tree.Nodes.Add("RULE");
tree.Nodes[1].Nodes.Add("CLASS");
tree.Nodes[1].Nodes[0].Nodes.Add("letter");
tree.Nodes[1].Nodes[0].Nodes.Add("ATTRIB");
tree.Nodes[1].Nodes[0].Nodes[1].Nodes.Add("class");
tree.Nodes[1].Nodes[0].Nodes[1].Nodes.Add("HASVALUE");
tree.Nodes[1].Nodes[0].Nodes[1].Nodes.Add(("'" + "current" + "'"));
tree.Nodes[1].Nodes.Add("PROPERTY");
tree.Nodes[1].Nodes[1].Nodes.Add("text-align");
tree.Nodes[1].Nodes[1].Nodes.Add("left");
tree.Nodes[1].Nodes.Add("PROPERTY");
tree.Nodes[1].Nodes[2].Nodes.Add("color");
tree.Nodes[1].Nodes[2].Nodes.Add("blue");
tree.Nodes.Add("RULE");
tree.Nodes[2].Nodes.Add("CLASS");
tree.Nodes[2].Nodes[0].Nodes.Add("locator");
tree.Nodes[2].Nodes.Add("CLASS");
tree.Nodes[2].Nodes[1].Nodes.Add("letter");
tree.Nodes[2].Nodes.Add("PROPERTY");
tree.Nodes[2].Nodes[2].Nodes.Add("background-color");
tree.Nodes[2].Nodes[2].Nodes.Add("#00ff00");
tree.Nodes[2].Nodes.Add("PROPERTY");
tree.Nodes[2].Nodes[3].Nodes.Add("color");
tree.Nodes[2].Nodes[3].Nodes.Add("red");
expectedIPCPNode.Nodes.Add((TreeNode)tree.Clone());
}
示例7: ExpectedRemoveUnderscoreTree
public void ExpectedRemoveUnderscoreTree()
{
expectedRUSNode.Nodes.Clear();
var tree = new TreeNode();
tree.Text = "ROOT";
tree.Nodes.Add("RULE");
tree.Nodes[0].Nodes.Add("CLASS");
tree.Nodes[0].Nodes[0].Nodes.Add("articleL1");
tree.Nodes[0].Nodes.Add("PARENTOF");
tree.Nodes[0].Nodes.Add("CLASS");
tree.Nodes[0].Nodes[2].Nodes.Add("pronunciationL2");
tree.Nodes[0].Nodes.Add("PRECEDES");
tree.Nodes[0].Nodes.Add("CLASS");
tree.Nodes[0].Nodes[4].Nodes.Add("pronunciationL3");
tree.Nodes[0].Nodes.Add("PSEUDO");
tree.Nodes[0].Nodes[5].Nodes.Add("before");
tree.Nodes[0].Nodes.Add("PROPERTY");
tree.Nodes[0].Nodes[6].Nodes.Add("content");
tree.Nodes[0].Nodes[6].Nodes.Add("1 ");
tree.Nodes.Add("RULE");
tree.Nodes[1].Nodes.Add("CLASS");
tree.Nodes[1].Nodes[0].Nodes.Add("entryL2");
tree.Nodes[1].Nodes.Add("PROPERTY");
tree.Nodes[1].Nodes[1].Nodes.Add("color");
tree.Nodes[1].Nodes[1].Nodes.Add("red");
expectedRUSNode.Nodes.Add((TreeNode)tree.Clone());
}
示例8: DragNode
private TreeNode DragNode(TreeNode desnode, TreeNode srcnode, DragDropEffects type)
{
if (this.m_isReadOnly) return null;
TreeNode newAddNode = null;
int des_key = Convert.ToInt32(((object[])desnode.Tag)[0]);
int des_parent_key = -100;
if (desnode.Parent != null)
{
des_parent_key = Convert.ToInt32(((object[])desnode.Parent.Tag)[0]);
}
int src_key = Convert.ToInt32(((object[])srcnode.Tag)[0]);
object[] des_key_s = new object[1];
des_key_s[0] = des_key;
object[] src_key_s = new object[1];
src_key_s[0] = src_key;
// 源结点父亲的后续清空
if (srcnode.Text.Contains(SubsequenceMark))
{
string[] Fields = new string[1];
Fields[0] = "SubsequenceID";
object[] Values = new object[1];
Values[0] = DBNull.Value;
Helper.SqlUpdateRecord(TblName, srcnode.Parent.Tag, Fields, Values, Conn);
srcnode.Text = srcnode.Text.Remove(srcnode.Text.Length - SubsequenceMark.Length);
}
if (type == DragDropEffects.Move) // 左键拖, 移动结点
{
// 把结点拖到自己的子孙上,是不允许的。
if (Helper.IsAncestorOffspring(srcnode, desnode))
{
MessageBox.Show("不能拖动到自己的子孙结点上。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return null;
}
// 把结点拖动到父亲或者自己上,无用操作。
if (srcnode.Parent == desnode || srcnode == desnode)
return null;
// 拖动到镜像结点上,是不允许的。
if (des_key > 0 && (des_parent_key == -3 || des_parent_key == -4))
{
MessageBox.Show("不能拖动到镜像结点上。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return null;
}
// 拖到实结点上
if (des_key > 0)
{
string[] Fields = new string[6];
Fields[0] = "PrequestLogic";
Fields[1] = "PrequestID1";
Fields[2] = "PrequestID2";
Fields[3] = "PrequestID3";
Fields[4] = "PrequestID4";
Fields[5] = "_AreaQuest";
object[] Values = new object[6];
Values[0] = DBNull.Value;
Values[1] = des_key;
Values[2] = DBNull.Value;
Values[3] = DBNull.Value;
Values[4] = DBNull.Value;
Values[5] = DBNull.Value;
Helper.SqlUpdateRecord(TblName, src_key_s, Fields, Values, Conn);
newAddNode = (TreeNode)(srcnode.Clone());
desnode.Nodes.Add(newAddNode);
newAddNode.ForeColor = ColorNodeNormal;
srcnode.Remove();
}
// 拖动到 “全部完成”“完成其一” 上
else if (des_key == -3 || des_key == -4)
{
if (desnode.Nodes.Count >= 5)
{
MessageBox.Show("不能在这里增加更多的前续条件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return null;
}
// 更新树结点, 这里有重排结点的动作。
TreeNode[] node_store = new TreeNode[4];
for (int i = 0; i < desnode.Nodes.Count; i++)
{
node_store[i] = (TreeNode)(desnode.Nodes[i].Clone());
}
desnode.Nodes.Clear();
TreeNode newNode = (TreeNode)(srcnode.Clone());
newNode.Nodes.Clear(); // 被拖动到前续任务集合里的结点,不需要显示子结点。
newNode.Text = newNode.Text.Contains(SubsequenceMark) ? newNode.Text.Remove(newNode.Text.Length - SubsequenceMark.Length) : newNode.Text;
newNode.ForeColor = ColorNodeClone;
newAddNode = newNode;
desnode.Nodes.Add(newNode);
for (int i = 0; i < 4; i++)
{
if (node_store[i] != null)
{
desnode.Nodes.Add(node_store[i]);
//.........这里部分代码省略.........
示例9: ExpectedParentDualClassTree
public void ExpectedParentDualClassTree()
{
expectedPDNode.Nodes.Clear();
var tree = new TreeNode();
tree.Text = "ROOT";
tree.Nodes.Add("RULE");
tree.Nodes[0].Nodes.Add("CLASS");
tree.Nodes[0].Nodes[0].Nodes.Add("locator");
tree.Nodes[0].Nodes.Add("PROPERTY");
tree.Nodes[0].Nodes[1].Nodes.Add("text-align");
tree.Nodes[0].Nodes[1].Nodes.Add("center");
tree.Nodes[0].Nodes.Add("PROPERTY");
tree.Nodes[0].Nodes[2].Nodes.Add("font-size");
tree.Nodes[0].Nodes[2].Nodes.Add("10");
tree.Nodes[0].Nodes[2].Nodes.Add("pt");
tree.Nodes.Add("RULE");
tree.Nodes[1].Nodes.Add("CLASS");
tree.Nodes[1].Nodes[0].Nodes.Add("locator");
tree.Nodes[1].Nodes.Add("CLASS");
tree.Nodes[1].Nodes[1].Nodes.Add("letter");
tree.Nodes[1].Nodes.Add("PROPERTY");
tree.Nodes[1].Nodes[2].Nodes.Add("font-weight");
tree.Nodes[1].Nodes[2].Nodes.Add("bold");
tree.Nodes[1].Nodes.Add("PROPERTY");
tree.Nodes[1].Nodes[3].Nodes.Add("font-size");
tree.Nodes[1].Nodes[3].Nodes.Add("20");
tree.Nodes[1].Nodes[3].Nodes.Add("pt");
tree.Nodes[1].Nodes.Add("PROPERTY");
tree.Nodes[1].Nodes[4].Nodes.Add("color");
tree.Nodes[1].Nodes[4].Nodes.Add("BLUE");
tree.Nodes[1].Nodes.Add("PROPERTY");
tree.Nodes[1].Nodes[5].Nodes.Add("text-align");
tree.Nodes[1].Nodes[5].Nodes.Add("center");
tree.Nodes.Add("RULE");
tree.Nodes[2].Nodes.Add("CLASS");
tree.Nodes[2].Nodes[0].Nodes.Add("subentry");
tree.Nodes[2].Nodes.Add("CLASS");
tree.Nodes[2].Nodes[1].Nodes.Add("letter");
tree.Nodes[2].Nodes.Add("PROPERTY");
tree.Nodes[2].Nodes[2].Nodes.Add("font-weight");
tree.Nodes[2].Nodes[2].Nodes.Add("bold");
tree.Nodes[2].Nodes.Add("PROPERTY");
tree.Nodes[2].Nodes[3].Nodes.Add("font-size");
tree.Nodes[2].Nodes[3].Nodes.Add("20");
tree.Nodes[2].Nodes[3].Nodes.Add("pt");
tree.Nodes[2].Nodes.Add("PROPERTY");
tree.Nodes[2].Nodes[4].Nodes.Add("color");
tree.Nodes[2].Nodes[4].Nodes.Add("GREEN");
expectedPDNode.Nodes.Add((TreeNode)tree.Clone());
}
示例10: CloneTest
public void CloneTest ()
{
TreeNode orig = new TreeNode ("text", 2, 3, new TreeNode [] { new TreeNode ("child", 22, 33) });
orig.Tag = FlatStyle.Flat;
orig.Checked = true;
orig.BackColor = SystemDrawingNamespace.Color.AliceBlue;
orig.ForeColor = SystemDrawingNamespace.Color.Beige;
TreeNode clone = (TreeNode)orig.Clone ();
Assert.AreEqual ("text", clone.Text, "#1");
Assert.AreEqual (2, clone.ImageIndex, "#2");
Assert.AreEqual (3, clone.SelectedImageIndex, "#3");
Assert.AreEqual (1, clone.Nodes.Count, "#4");
Assert.AreEqual (FlatStyle.Flat, clone.Tag, "#5");
Assert.IsTrue (clone.Checked, "#6");
Assert.AreEqual ("child", clone.Nodes [0].Text, "#10");
Assert.AreEqual (22, clone.Nodes [0].ImageIndex, "#11");
Assert.AreEqual (SystemDrawingNamespace.Color.AliceBlue, clone.BackColor, "#12");
Assert.AreEqual (SystemDrawingNamespace.Color.Beige, clone.ForeColor, "#13");
}
示例11: TestTreeNodeClone2
[Test] // bug 661753
public void TestTreeNodeClone2 ()
{
// Cannot test ImageIndex and ImageKey properties at the same time,
// as one excludes the other. So this method is for Keys only.
TreeNode orig = new TreeNode ();
orig.ImageKey = "MyImageKey";
orig.SelectedImageKey = "MySelectedImageKey";
orig.StateImageKey = "MyStateImageKey";
TreeNode clone = orig.Clone () as TreeNode;
Assert.AreEqual (orig.ImageKey, clone.ImageKey, "#01");
Assert.AreEqual (orig.SelectedImageKey, clone.SelectedImageKey, "#02");
Assert.AreEqual (orig.StateImageKey, clone.StateImageKey, "#03");
}
示例12: ExpectedSingleClassCSS
public void ExpectedSingleClassCSS()
{
expectedSCNode.Nodes.Clear();
var SCtree = new TreeNode();
SCtree.Text = "ROOT";
SCtree.Nodes.Add("RULE");
SCtree.Nodes[0].Nodes.Add("CLASS");
SCtree.Nodes[0].Nodes[0].Nodes.Add("letter");
SCtree.Nodes[0].Nodes.Add("PROPERTY");
SCtree.Nodes[0].Nodes[1].Nodes.Add("text-align");
SCtree.Nodes[0].Nodes[1].Nodes.Add("center");
SCtree.Nodes[0].Nodes.Add("PROPERTY");
SCtree.Nodes[0].Nodes[2].Nodes.Add("font-weight");
SCtree.Nodes[0].Nodes[2].Nodes.Add("bold");
SCtree.Nodes[0].Nodes.Add("PROPERTY");
SCtree.Nodes[0].Nodes[3].Nodes.Add("font-size");
SCtree.Nodes[0].Nodes[3].Nodes.Add("24");
SCtree.Nodes[0].Nodes[3].Nodes.Add("pt");
SCtree.Nodes[0].Nodes.Add("PROPERTY");
SCtree.Nodes[0].Nodes[4].Nodes.Add("font-family");
SCtree.Nodes[0].Nodes[4].Nodes.Add("\"" + "Times New Roman" + "\"");
SCtree.Nodes[0].Nodes[4].Nodes.Add("serif");
expectedSCNode.Nodes.Add((TreeNode)SCtree.Clone());
}
示例13: cloneTreeNode
public static TreeNode cloneTreeNode(TreeNode treeNode)
{
if (treeNode == null)
return null;
return (TreeNode) treeNode.Clone();
}
示例14: NudgeUp
private static void NudgeUp(TreeNode node)
{
if (node == null)
{
return;
}
if (node.Index == 0)
{
return;
}
int newIndex = node.Index - 1;
TreeNode nodeClone = (TreeNode)node.Clone();
node.Parent.Nodes.Insert(newIndex, nodeClone);
node.Parent.Nodes.Remove(node);
ReOrderSiblings(nodeClone);
nodeClone.TreeView.SelectedNode = nodeClone;
}
示例15: DoReassignment
private void DoReassignment(TreeNode Child, TreeNode NewParent)
{
if ((Child != null) && (NewParent != null))
{
String PrevParent = Child.Parent.Text;
TreeNode NewNode = (TreeNode)Child.Clone();
((UnitHierarchyNode)NewNode.Tag).ParentUnitKey = ((UnitHierarchyNode)NewParent.Tag).MyUnitKey;
InsertAlphabetically(NewParent, NewNode);
NewNode.Expand();
NewParent.Expand();
NewParent.BackColor = Color.White;
FChangedParents.Add(new Tuple <string, long, long>(
((UnitHierarchyNode)NewParent.Tag).Description,
((UnitHierarchyNode)NewNode.Tag).MyUnitKey,
((UnitHierarchyNode)NewNode.Tag).ParentUnitKey));
FStatus += String.Format(Catalog.GetString("{0} was moved from {1} to {2}.\r\n"),
Child.Text, PrevParent, NewParent.Text);
txtStatus.Text = FStatus;
//Select the New Node in the tree view
SelectNode(NewNode);
trvUnits.SelectedNode = NewNode;
//Remove Original Node
Child.Remove();
FPetraUtilsObject.SetChangedFlag();
}
}